Please give this test! lifanov@mail.ru Oh, I has mixed too, but now it works, thank you :) void fallBack(int angle, int M, int curEnergy, int curAmmo); void advance(int angle, int M, int curEnergy, int curAmmo); int findX(int curEnergy); int main() { int curEnergy, curAmmo; char behaviour; int M, MP, angle; int N, NP, offset; scanf_s("%i %i", &curEnergy, &curAmmo); scanf_s(" %c", &behaviour); scanf_s("%i %i %i", &M, &MP, &angle); if (behaviour == 'A') { scanf_s("%i %i", &N, &NP); } else if (behaviour == 'P') { scanf_s("%i", &offset); offset *= -1; } while (1) { switch (behaviour) { case 'A': if ((N*NP) > (M*MP * 3)) { advance(angle, M, curEnergy, curAmmo); return 0; } else { fallBack(angle, M, curEnergy, curAmmo); return 0; } case 'D': if ((M * 20) >= curAmmo) { fallBack(angle, M, curEnergy, curAmmo); return 0; } else { behaviour = 'G'; break; } case 'G': if (M == 0) { printf("STOP"); } if (abs(angle) < 5) { int P = (int)fmin(20, curAmmo); printf("FIRE %i", P); return 0; } else if (angle >= 5) { printf("LEFT %i", findX(curEnergy)); return 0; } else if (angle <= -5) {
printf("RIGHT %i", findX(curEnergy)); return 0; } case 'P': if (M != 0) { behaviour = 'D'; break; } else { if (offset >= -180 && offset <= -160) { printf("BACKWARD %i", findX(curEnergy)); return 0; } else if (offset > -160 && offset < -90) { printf("RIGHT %i", findX(curEnergy)); return 0; } else if (offset >= -90 && offset < -20) { printf("LEFT %i", findX(curEnergy)); return 0; } else if (offset >= -20 && offset <= 20) { printf("FRONT %i", findX(curEnergy)); return 0; } else if (offset > 20 && offset <= 90) { printf("RIGHT %i", findX(curEnergy)); return 0; } else if (offset > 90 && offset < 160) { printf("LEFT %i", findX(curEnergy)); return 0; } else if (offset >= 160 && offset <= 180) { printf("BACKWARD %i", findX(curEnergy)); return 0; } } } } return 0; } void fallBack(int angle, int M, int curEnergy, int curAmmo) { if (abs(angle) >= 5 || M == 0) { printf("BACKWARD %i", findX(curEnergy)); } else { int P = (int)fmin(20, curAmmo); printf("FIRE %i", P); } } void advance(int angle, int M, int curEnergy, int curAmmo) { if (abs(angle) >= 10 || M == 0) { printf("FRONT %i", findX(curEnergy)); } else { int P = (int)fmin(20, curAmmo); printf("FIRE %i", P); } } int findX(int curEnergy) { int X; if (curEnergy > 100) { X = 100; } else { X = curEnergy; } return X; } can you tell me test 35? i have WA Can somebody help me? I don't know what to do. I tried a lot of tests and all answers were correct. My code: #include<stdio.h> #include<conio.h> #include<math.h> #include<stdlib.h> #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) int main() { long a, b, x, y, z, p, q; char ch; scanf("%d%d", &a, &b); scanf("%s", &ch); scanf("%d%d%d", &x, &y, &z); a=min(a, 100); if(ch=='A') scanf("%d%d", &p, &q); if(ch=='P') scanf("%d", &p); if(ch=='P') if(x>0) ch='D'; else { if((abs(p)>20)&&(abs(p)<160)){ if(((p>20)&&(p<=(90)))||((p<=-90)&&(p>-160))) printf("LEFT %d", a); else printf("RIGHT %d", a); } else if(abs(p)<=20) printf("FRONT %d", a); else printf("BACKWARD %d", a); } if(ch=='D') if((x>0)&&((x*20)>=b)) if(abs(z)<5) printf("FIRE %d", min(20, b)); else printf("BACKWARD %d", a); else ch='G'; if(ch=='G') { if(x==0) printf("STOP"); else { if(abs(z)<5) printf("FIRE %d", min(20, b)); if(z>=5) printf("LEFT %d", a); if(z<=-5) printf("RIGHT %d", a); } } if(ch=='A') if((p*q)>(3*(x*y))) if((x>0)&&(abs(z)<10)) printf("FIRE %d", min(20, b)); else printf("FRONT %d", a); else if((x>0)&&(abs(z)<5)) printf("FIRE %d", min(20, b)); else printf("BACKWARD %d", a); } My program passed all tests from forum, but It gets WA28 Here is my code: Var ygol,arm,otkl,energy,us,ensrus,enemys,ensrzapas : int64; s : string; Function Min(x,y : int64):int64; Begin if x > y then Min := y Else Min := x; End; Procedure Oxrana; Begin if enemys = 0 then Writeln('STOP') Else if Abs(ygol) < 5 then Writeln('FIRE ',Min(20,arm)) Else if ygol > 0 then Writeln('LEFT ',Min(100,energy)) Else Writeln('RIGHT ',Min(100,energy)); End; Procedure Atack; Begin if us*ensrus > enemys*ensrzapas*3 then if Abs(ygol) < 10 then Writeln('FIRE ',Min(20,arm)) Else Writeln('FRONT ',Min(100,energy)) Else if Abs(ygol) < 5 then Writeln('FIRE ',Min(20,arm)) Else Writeln('BACKWARD ',Min(100,energy)) End; Procedure Defence; Begin if enemys*20 >= Arm then if Abs(ygol) < 5 then Writeln('FIRE ',Min(20,arm)) Else Writeln('BACKWARD ',Min(100,energy)) Else Oxrana; End; Procedure Patrul; Var t : longint; Begin t := otkl; if otkl < 0 then Otkl := Otkl+360; if enemys > 0 then Defence Else if (Otkl>=160) and (otkl <= 200) then Writeln('BACKWARD ',Min(100,energy)) Else if ((otkl >= 0) and (otkl <= 20) or (otkl >= 340) and (otkl <= 360)) then Writeln('FRONT ',Min(100,energy)) Else if t > 0 then Writeln('LEFT ',Min(100,energy)) Else Writeln('RIGHT ',Min(100,energy)); End; BEGIN Readln(Energy,Arm); Readln(s); Read(enemys,ensrzapas,ygol); if Pos('A',s) <> 0 then Begin Read(us,ensrus); Atack; End; if Pos('D',s) <> 0 then Defence; if Pos('G',s) <> 0 then Oxrana; if Pos('P',s) <> 0 then Begin Read(otkl); Patrul; End; END. This test, please: 4 100 P 0 123 45 128 I hope it'll help you! :))) program URAL1299(input,output); var n,np,m,mp,p,x,yg:longint; ch:char; procedure gfire; begin if (abs(yg)>=10)or(m=0) then writeln('FRONT ',x) else writeln( 'FIRE ',p); end; procedure bfire; begin if (abs(yg)>=5)or(m=0) then writeln('BACKWARD ',x) else writeln('FIRE ',p); end; procedure attack; begin readln(n,np); if n*np>=3*m*mp then gfire else bfire; end; procedure guard; begin if m=0 then begin writeln('STOP');exit; end; if abs(yg)<5 then writeln('FIRE ',p) else begin if yg>=+5 then writeln( 'LEFT ',x); if yg<=-5 then writeln('RIGHT ',x); end; end; procedure defense; begin if m*20>=p then bfire else guard; end; procedure patrol; begin readln(yg);//yg:=yg+180; if m>0 then defense else begin if abs(yg)<=20 then writeln('FRONT ',x) else if abs(yg)>=160then writeln('BACKWARD ',x)else begin if yg<-90 then yg:=+180-abs(yg); if yg>+90 then yg:=-180+abs(yg); if yg> 0 then writeln('LEFT ',x) else writeln('RIGHT ',x); end; end; end; begin readln(x,p); if x>100 then x:=100; if p> 20 then p:= 20; readln(ch);readln(m,mp,yg); case ch of 'G':guard; 'A':attack; 'P':patrol; 'D':defense; end; end. >if x>100 then x:=100; >if p> 20 then p:= 20; You have to use initial values, while finding solution. > if n*np>=3*m*mp This has to be n*np>3*m*mp My solution failed on 14th test, because mine was written like: if n*np*3>m*mp
I always have WA1? Give me some tests My code is here: ====================================== #include <iostream> #include <math.h> using namespace std; void Attack(int &, int &, int &, int &); void Guard(int &, int &); void Defense(int &); void Patrol(int &, int &); void OffensiveStrike(int &, int &); void RetreatStrike(int &, int &); void LEFT(int &); void RIGHT(int &); void FRONT(int &); void BACKWARD(int &); void FIRE(int &); void STOP(); int X,P; int M,MP,MA; int main() { cin >> X >> P;
char model; cin >> model;
cin >> M >> MP >> MA;
if ('A'==model) { int N,NP; cin >> N >> NP; Attack(N,NP,M,MP); } else if ('G'==model) Guard(M,MA); else if ('D'==model) Defense(M); else if ('P'==model) { int A; cin >> A; Patrol(M,A); }
} void Attack(int &N, int &NP, int &M, int &MP) { if (N*NP>M*MP*3) OffensiveStrike(M,MA); else RetreatStrike(M,MA); } void Guard(int &M, int &MA) { if (0==M) STOP; else if (MA>=5) LEFT(X); else if (MA<=-5) RIGHT(P); else FIRE(P); } void Defense(int &M) { if (M*20>=P) RetreatStrike(M,MA); else Guard(M,MA); } void Patrol(int &M, int &A) { if (M>0) Defense(M); else if (abs(A)<=20 || 180-abs(A)<=20) { if (abs(A)<=20) FRONT(X); else BACKWARD(X); } else if ((A>=90 && A<160) || (A>=-90 && A<-20)) RIGHT(X); else LEFT(X);
}
void OffensiveStrike(int &M, int &MA) { if (abs(MA)>=10 || 0==M) FRONT(X); else FIRE(P); } void RetreatStrike(int &M, int &MA) { if (abs(MA)>=5 || 0==M) BACKWARD(X); else FIRE(P); } void LEFT(int &X) { if (X>100) cout << "LEFT 100"; else cout << "LEFT " << X; } void RIGHT(int &X) { if (X>100) cout << "RIGHT 100"; else cout << "RIGHT " << X; } void FRONT(int &X) { if (X>100) cout << "FRONT 100"; else cout << "FRONT " << X; } void BACKWARD(int &X) { if (X>100) cout << "BACKWARD 100"; else cout << "BACKWARD " << X; } void FIRE(int &P) { if (P>20) cout << "FIRE 20"; else cout << "FIRE " << P; } void STOP() { cout << "STOP"; } Try this test: 4 23 P 0 0 0 -23 Correct answer is "RIGHT 4" In patrolling mode when if angle is in range -20..20 then robot should move front and if angle is greater than 160 or less then -159 backward. This fact costed me 15 submissions. Hope it will help someone. >>if angle is greater than 160 or less then -159 backward You aren't right. Angle must be >= 160 or < -159 (<= -160). I fixed this and got AC. "In all these cases X is calculated as follows: If the robot’s power supply has more than 100 energy units available, then X = 100; otherwise, X is the amount of power units remaining. Similarly, P is calculated as the smallest of two values: 20 and the actual amount of ammunition units remaining." You should use this rule only while writing result command, and use default amount of ammunition and energy while calculating. In my solution there was such bug, that in patrolling mode, after switching to defence mode my program hadn't exited and tried to move or turn. What is test 32?I can't find what's wrong with my code. Please give me some hints? Thanks. You don't apply this rule correctly: "According to the “Defense” pattern, robot’s actions are defined as follows: calculate the number of enemies and multiply it by 20. If the result is not less than the amount of ammunition units left, the robot will “Retreat and Return Fire”. Otherwise, it will act as if following the “Guard” pattern." Edited by author 04.11.2010 06:24 Some new tests by Alexander Kouprin were added. 38 authors lost AC after rejudge. We have some mismatch in english and russian versions of problem statements: 1.1. According to the “Defense” pattern, robot’s actions are defined as follows: calculate the number of enemies and multiply it by 20. If the result is __( greater )__ than the amount of ammunition units left, the robot will “Retreat and Return Fire”. Otherwise, it will act as if following the “Guard” pattern. 1.2. При реализации модели поведения «защита», робот действует так: если количество врагов умноженное на 20 __( не меньше )__ количества единиц вооружения робота, то робот отступает отстреливаясь. Иначе он действует согласно стратегии «охрана». 2.1. Similarly, when the battle-robot “Advances and Returns Fire”, it checks the angle to the most dangerous enemy. If the angle is 10 degrees or more, or there are no enemies, the robot just moves __( backward )__ or shoots otherwise. 2.2. «Наступает, отстреливаясь» означает, что если угол до самой опасной вражеской цели меньше 10, то робот делает выстрел. Иначе, или если врагов нет, движется __( вперед )__. 3.1. None of these integers exceeds __( 100000 )__. 3.2. Все числа, во входном файле целые и не превосходят __( 1000000 )__. ? What statement ( eng || rus ) should be consider as correct? I think, the English one. At least when I solved this problem, solution written on the basis of russian statement was getting WA because of (1.2) Will Admins correct russian statement? (or maybe english)? 1 and 2: the correct statement is the Russian one. We apologize to all programmers who solved this problem using the English statement. We added some tests that should have different answers according to the old English and Russian statements, so some authors got WA on them. Now the English statement should be OK. If you find more mistakes, please, write about them. 3: all integers in fact are no greater than 1000. This limitation has been updated in both Russian and English versions. Don't You forget to add this changes (and rejudges) to "Site News"? hello .this is my programm #include<stdio.h> //#include<conio.h> #include<math.h> // long energy,armor; long kol_vrag,sr_energy_vrag,ugol; long kol_robot,sr_energy_robot; long ugol_otklona; //------------------------ void Input(void); void DG(void); void DD(void); void DA(void); void DP(void); int Min(const long x,const long y); void Back(void); void Atak(void); //------------------------ void main(void) { //clrscr(); // Input(); // //getch(); } //------------------------ void Input(void) { char vid; // scanf("%ld",&energy); scanf("%ld",&armor); // scanf("%c",&vid); scanf("%c",&vid); scanf("%ld",&kol_vrag); scanf("%ld",&sr_energy_vrag); scanf("%ld",&ugol); // switch(vid){ case 'G':DG();break; case 'D':DD();break; case 'A':DA();break; case 'P':DP();break; } } // void DG(void) { if(!kol_vrag) printf("STOP"); else if(abs(ugol)<5) printf("FIRE %d",Min(20,armor)); else { if(ugol>=5) printf("LEFT %d",Min(100,energy)); else if(ugol<=(-5)) printf("RIGHT %d",Min(100,energy)); } } // void DD(void) { if((20*kol_vrag)>=armor) Back(); else DG(); } // void DA(void) { scanf("%ld",&kol_robot); scanf("%ld",&sr_energy_robot); // if((kol_robot*sr_energy_robot)>(kol_vrag*sr_energy_vrag*3)) Atak(); else Back(); } // void DP(void) { scanf("%ld",&ugol_otklona); // if(kol_vrag) DD(); else if((abs(ugol_otklona)>20)&&(abs(ugol_otklona)<160)){ if( ( (ugol_otklona>20)&&(ugol_otklona<=(90) ))|| ((ugol_otklona<=-90)&&(ugol_otklona>-160) ) ) printf("LEFT %d",Min(100,energy)); else printf("RIGHT %d",Min(100,energy)); } else printf("FRONT %d",Min(100,energy)); } // int Min(const long x,const long y) { int r=x; // if(y<r) r=y; // return(r); } // void Back(void) { if(abs(ugol)<5) printf("FIRE %d",Min(20,armor)); else printf("BACKWARD %d",Min(100,energy)); } // void Atak(void) { if(abs(ugol)<10) printf("FIRE %d",Min(20,armor)); else printf("FRONT %d",Min(100,energy)); } Test 24: Patrolling, no enemies, angle to the next waypoint <= -160. Test 27: Patrolling, no enemies, angle to the next waypoint >= 160. Answer for both tests BACKWARD. Edited by author 06.02.2007 05:29 Test 28: Patrolling, no enemies, angle to the next waypoint 159. Test 29: Patrolling, no enemies, angle to the next waypoint -159. > Similarly, when the battle-robot “Advances and Returns Fire”, it checks the angle to the most dangerous enemy. If the angle is 10 degrees or more, or there are no enemies, the robot just moves backward or shoots otherwise. Not backward, but forward. Note that it does not matter whether the robot is moving forward or backward while following the route. You should consider this when calculating the turn direction - the turn angle should be minimal. This means that when you want to reach a point at angle A, you can either move FRONT at angle A, or move BACK at angle A + 180, so you must choose the one closer to your current direction. That's why we have LEFT in first sample: -100 == 80, and 80 is closer to 0 than -100 is, so we turn LEFT to reach 80. When they say "angle to the next waypoint exceeds 20 degrees by absolute value", they actually mean "angle or Abs(180 - Abs(Angle)) exceeds 20 degrees by absolute value". var x,p,col,m,mp,ygol,n,np,otk:longint; c:char; procedure oxrana; begin if m=0 then writeln('STOP') else if abs(ygol)<5 then writeln('FIRE ',p) else if ygol<0 then writeln('RIGHT ',x) else writeln('LEFT ',x); end; procedure zashita; begin if m*20>=p then if abs(ygol)<5 then writeln('FIRE ',p) else writeln('BACKWARD ',x) else oxrana; end; procedure ataka; begin readln(n,np); if n*np>m*mp*3 then if abs(ygol)<10 then writeln('FIRE ',p) else writeln('FRONT ',x) else if abs(ygol)<5 then writeln('FIRE ',p) else writeln('BACKWARD ',x); end; procedure patrul; var ygl:longint; begin readln(otk); if otk<-90 then ygl:=180-abs(otk); if otk>90 then ygl:=-(180-abs(otk)); if abs(ygol)<5 then zashita else if (abs(otk)>20) then if ygl<0 then writeln('LEFT ',x) else writeln('RIGHT ',x) else writeln('BACKWARD ',x) end; begin readln(x,p); if x>100 then x:=100; IF P>20 then p:=20; readln(c); readln(m,mp,ygol); if c='G' then oxrana; if c='D' then zashita; if c='A' then ataka; if c='P' then patrul; end. var x,p,col,m,mp,ygol,n,np,otk:longint; c:char; procedure oxrana; begin if m=0 then writeln('STOP') else if abs(ygol)<5 then writeln('FIRE ',p) else if ygol<0 then writeln('RIGHT ',x) else writeln('LEFT ',x); end; procedure zashita; begin if m*20>=p then if abs(ygol)<5 then writeln('FIRE ',p) else writeln('BACKWARD ',x) else oxrana; end; procedure ataka; begin readln(n,np); if n*np>m*mp*3 then if abs(ygol)<10 then writeln('FIRE ',p) else writeln('FRONT ',x) else if abs(ygol)<5 then writeln('FIRE ',p) else writeln('BACKWARD ',x); end; procedure patrul; begin readln(otk); if (m<>0) then zashita else begin if abs(otk)<=20 then writeln('FRONT ',x) else if (otk<=-159) or (otk>=160) then writeln('BACKWARD ',x) else begin if otk<-90 then otk:=180-abs(otk); if otk>90 then otk:=-(180-abs(otk)); if otk<0 then writeln('LEFT ',x) else writeln('RIGHT ',x); end; END; end; begin readln(x,p); if x>100 then x:=100; IF P>20 then p:=20; readln(c); readln(m,mp,ygol); if c='G' then oxrana; if c='D' then zashita; if c='A' then ataka; if c='P' then patrul; end. 1 1 P 0 0 0 165 STOP Your answer: STOP Correct answer: BACKWARD 1 Sample input #1 100 100 P 0 0 0 -100 Sample output #1 LEFT 100 Why LEFT 100??? Why not RIGHT 80??? if input 0 100 G 1 123 45 What output??? My AC prg outputs: LEFT 0 Who know what is it??? !!!!!!I am very HAPPY!!!!!!!!!!!!!!!!!!!! |
|