Last active
August 29, 2015 13:57
-
-
Save moehuster/9545131 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstdlib> | |
#include <cstring> | |
int g_life[5]={0}; | |
int red_next[5]={2,0,3,4,1}; | |
int blue_next[5]={1,2,4,0,3}; | |
const char* g_name[5]={"dragon","ninja","iceman","lion","wolf"}; | |
struct warrior{ | |
int id; | |
int type; | |
int strength; | |
char name[16]; | |
}; | |
struct league{ | |
int type; //0->red 1->blue | |
int life; //headquarter total life | |
int num; //total warriors | |
int pre; //previous warrior | |
int heros[5];//0:dragon,1:ninja,2:iceman,3:lion,4:wolf | |
bool make_warrior(warrior& w); | |
league(int t,int l):type(t),life(l),num(0){ | |
pre=type?4:0; | |
memset(heros,0,sizeof(heros)); | |
} | |
}; | |
int main() | |
{ | |
int num,life; | |
bool fr,fb; | |
scanf("%d",&num); | |
for (int j=1; j<=num; j++){ | |
printf("Case:%d\n",j); | |
fr=fb=true; | |
scanf("%d",&life); | |
for (int i=0; i<5; i++) | |
scanf("%d",g_life+i); | |
warrior w; | |
league red(0,life); | |
league blue(1,life); | |
for (int i=0; fr||fb; i++){ | |
if (red.make_warrior(w)){ | |
printf("%03d red %s %d born with strength %d,%d %s in red headquarter\n", | |
i,w.name,w.id,w.strength,red.heros[w.type],w.name); | |
} else if (fr){ | |
fr=false; | |
printf("%03d red headquarter stops making warriors\n",i); | |
} | |
if (blue.make_warrior(w)){ | |
printf("%03d blue %s %d born with strength %d,%d %s in blue headquarter\n", | |
i,w.name,w.id,w.strength,blue.heros[w.type],w.name); | |
} else if (fb){ | |
fb=false; | |
printf("%03d blue headquarter stops making warriors\n",i); | |
} | |
} | |
} | |
} | |
bool league::make_warrior(warrior &w) | |
{ | |
int i,n,*next; | |
next=type?blue_next:red_next; | |
for(i=0; i<5; i++){ | |
if(life>=g_life[next[pre]])break; | |
pre=next[pre]; | |
} | |
if (i==5) return false; | |
n=pre=next[pre]; | |
w.type=n; | |
w.id=++num; | |
w.strength=g_life[n]; | |
strcpy(w.name,g_name[n]); | |
life-=g_life[n]; | |
++heros[n]; | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment