ACM题目超时了
程序代码:
#include <STDIO.H> #include <STRING.H> typedef struct body { int hp; int str; int spd; }bodystate; bodystate getstate(char s[]) { bodystate c; int i,j; c.hp=0; c.str=1; c.spd=0; for(i=0;i<strlen(s);i++) { c.hp+=(83-s[i])*(83-s[i]); } c.hp=300-c.hp%97; for(i=0;i<strlen(s);i++) { c.str*=s[i]; } c.str=22+c.str%79; for(i=0;i<strlen(s);i++) for(j=i+1;j<strlen(s);j++) { c.spd+=s[i]*s[j]; } c.spd=c.spd%11; return c; } int main() { int t; int time; char a[20],b[20]; bodystate bodya,bodyb; scanf("%d",&t); while(t--) { scanf("%s%s",a,b); bodya=getstate(a); bodyb=getstate(b); for(time=1;;time++) { if(bodya.hp<=0||bodyb.hp<=0) break; if(time%(20-bodya.spd)==0) bodyb.hp-=bodya.str; if(time%(20-bodyb.spd)==0) bodya.hp-=bodyb.str; } if(bodya.hp==0&&bodyb.hp==0) printf("tie\n"); else if(bodya.hp<=0) printf("lose\n"); else if(bodyb.hp<=0) printf("win\n"); } return 0; }
题目地址:http://172.19.141.56/OJ/Problem.aspx?id=91
求教啊!