Common Boardinclude <iostream> using namespace std; int main() { int N=0,a=0,b=0; cin>>N; a=(N/100000)+(N/10000-N/100000*10)+(N/1000-N/10000*10); b=(N/100-N/1000*10)+(N/10-N/100*10)+(N-N/10*10); if(a-1==b){ cout << "YES\n"; } else { cout << "NO\n"; } return 0; } What's in test 2? As I understand, it's not necessary that number of people in each team is the same. my prog got AC but on 65,85,105... it answers 2,but I think the answer is 1. yes,my second prog answers 1 and got AC too. a 20-number period incorrect! Edited by author 20.05.2013 20:57 Thank you. New tests were added. 235 authors lost AC after rejudge. Edited by author 27.05.2014 13:18 Edited by author 27.05.2014 13:18 Incorrect; the answer to those is 2. #include<iostream> #include<stack> #include<math.h> #include<iomanip> float next_value = 0; std::stack<float> my_stack; int main() { int a = 0; while (std::cin >> next_value) { if (a == 65536) break; if (0 <= next_value && next_value <= pow(10.0, 18)) { my_stack.push(next_value); } else continue; a++; } while (!my_stack.empty()) { std::cout << std::fixed << std::setprecision(4) << sqrt(my_stack.top()) << std::endl; my_stack.pop(); } return 0; } import java.util.*; import java.io.*; public class root { public static void main(String[] args) { Scanner in = new Scanner(System.in);
ArrayList<Long> list = new ArrayList<Long>();
while (in.hasNextLine()) { list.add(in.nextLong()); }
Collections.reverse(list);
for (long x : list) { System.out.printf("%.4f", Math.sqrt(x)); System.out.println(); } } } Works on my computer with the given input. Edited by author 31.01.2015 06:20 For example if I take N =4. then i write: 10 12 9 3 15 10 11 13 What will I get? i think that no such input like yours. ( my ac solution does not handle it properly. ) you should write it in this way (only one digit for one number per line): 1 1 0 2 9 3 1 1 5 0 1 1 1 3 and therefore N = 7 #include <stdio.h> int main(void) {
int car_num, min, i, arr[100], sum = 0;
scanf("%d %d", &car_num, &min);
for(i = 0; i < min; i++) { scanf("%d", &arr[i]); if(sum + arr[i] - car_num < 0) sum += 0; else sum = sum + arr[i] - car_num; }
printf("%d", sum);
return 0;
} You're not printing a newline after printing the answer ... though I think the real issue is different: I don't believe you're handling the following cases correctly. Try this test case 5 3 6 1 2 and this one 5 3 6 1 7 Good luck! -- DC Edited by author 30.01.2015 21:10 I've checked all the tests on the forum, but all of them actually wokred. What's wrong with the code? type Otrezok=record beginning,ending:real; colour:string; end; type Point=record mean,predel:real; end; var a:array[0..50000] of Otrezok; b:array[0..50002] of Point; i,N,j,s:integer; k,j1,j2,max,f1,f2:real; t,f3:string; function colour(x:real;H:integer):string; var j:integer; begin for j:=0 to H do begin if (x>=a[j].beginning) and (x<=a[j].ending) and (a[j].colour=' w') then colour:='w'; if (x>=a[j].beginning) and (x<=a[j].ending) and (a[j].colour=' b') then colour:='b'; end; end; begin a[0].beginning:=0; a[0].ending:=1000000000; a[0].colour:=' w'; readln(N); for i:=1 to N do begin readln(f1,f2,f3); if f1<f2 then begin a[i].beginning:=f1; a[i].ending:=f2; a[i].colour:=f3; end; end; for j:=1 to N do begin b[j].predel:=0; b[j+N].predel:=0; b[j].mean:=a[j].beginning; b[j+N].mean:=a[j].ending; end; b[0].predel:=0; b[0].mean:=0; for i:=(2*N-1) downto 1 do for j:=1 to i do begin if b[j].mean>b[j+1].mean then begin k:=b[j+1].mean; b[j+1].mean:=b[j].mean; b[j].mean:=k; end; if (b[j].mean=b[j+1].mean) then b[j+1].mean:=0 end;
for i:=1 to 2*N do begin if (b[i].mean<>0) and (colour(b[i].mean,N)<>colour(b[i].mean+0.1,N)) or (colour(b[i].mean,N)<>colour(b[i].mean-0.1,N)) then b[i].predel:=1; if b[i].mean=0 then b[i].predel:=0; end; t:=colour(0,N); s:=0; for i:=0 to 2*N do begin if (b[i].predel=1) then begin s:=s+1; k:=b[s].mean; b[s].mean:=b[i].mean; b[i].mean:=k; end; end; for i:=s downto 0 do b[i+1].mean:=b[i].mean; b[s+2].mean:=1000000000; max:=0; b[0].mean:=0; for i:=1 to s+2 do begin if t='w' then begin if (i mod 2)=0 then begin if (b[i].mean-b[i-1].mean)>max then begin max:=b[i].mean-b[i-1].mean; j1:=b[i-1].mean; j2:=b[i].mean; end; end; end; if t='b' then begin if (i mod 2)=1 then begin if b[i].mean-b[i-1].mean>max then begin max:=b[i].mean-b[i-1].mean; j1:=b[i-1].mean; j2:=b[i].mean; end; end; end; end; write(Round(j1),' ',Round(j2)); end. [deleted] P.S. Don't EVER forget to initialize your variables. Edited by author 30.01.2015 01:18 Edited by author 30.01.2015 01:19 This tests helped me with WA3, WA5 and WA10, but now I'm stuck at test 20. Any hints? 4 9 010000010 111010111 101111101 000101000 answer: 9 4 5 11000 01100 00110 00011 answer: 4 5 5 11100 11110 11111 01111 00111 answer: 3 4 9 100111100 100100100 100100100 111100111 answer: 6 This helped with test 20, now WA31 to overcome! 4 5 00100 01110 01010 11011 answer: 5 In the name of who make the worlds Hello When I running my code in vb 2010 my code is correct, but when I submit in site, site saying me "wrong answer" with 8 "test#". What's the problem? Is it in my code or on site my code: #include <iostream> #include <cmath> using namespace std; int main() { //description int n , k ; //input cin >> n >> k ; //calculating if ( ( ( 2 * n ) % k ) == 0 ) { n = ( 2 * n ) / k ; } else { n = ( 2 * n ) / k ; n ++ ; } //output cout << n ; //end return 0; } Thank you Bye A.J.Fater You need set. Think how to use it here No, you don't need a set. Any simple linear data structure will do. check this test: tram,tram Right answer is Tram driver :) Edited by author 29.01.2015 16:30 ok, now I have AC :) Edited by author 29.06.2009 17:03 If you have WA15, try this test: 5 1 1 3 1 2 1 4 1 1 My AC program outputs: First player wins flying to airport 2 Read carefully: "...If there are several such airports, the program should find one of them that has the minimal number..." Tnx :) it helped! but your test data shoud be: 5 1 1 3 1 2 1 4 1 5 :D Does everyone speak at least one dialect? Why? --- My fault Edited by author 29.06.2013 02:09 this problem is very very easy ,some hints from AC code ......... for(i=0;i<k;i++){ ......... s+=n-t; } n-=s; if(n<0) n=0; ...... I didnot undestand why //Сложность: 308 // ????!!! The issue is for minimization. Edited by author 28.01.2015 00:41 var a: int64; n:int64; sum:int64; i,k:integer; begin read(n,k); a:=0; sum:=0; for i:=1 to k do begin read(a); sum:=sum+a; end; if sum-n >=0 then write(sum - n) else write('0'); end. Edited by author 03.01.2015 03:26 Edited by author 03.01.2015 03:27 Algorithm mistake, example: 2 3 2 2 2 Your answer is 4, but should be 2. Edited by author 27.01.2015 23:29 Issue resolved, see below! Edited by author 27.01.2015 05:49 So, be careful if manually calculating - subtle fact is that the aggregate majority of a sequence of numbers may not actually represent the majority from each individual group, for example (from another thread): 5 5 5 5 5 5 => 9 But at first, I naively calculated (5+5+5)/2 + 1, which works in other group sizes but not for duplicate numbers. So, just keep that in mind :) Edited by author 27.01.2015 05:49 #include<iostream.h> int t[12][2]; int a,b; void print() { int s,x,y,i; s=0; for (i=1;i<=8;i++) { x=t[i][1]; y=t[i][2]; if ((b+x>=1) && (b+x<=8) && (a+y>=1) && (a+y<=8)) s++; } cout<<s<<endl; } void in() { t[1][1]=2;t[1][2]=1; t[2][1]=1;t[2][2]=2; t[3][1]=2;t[3][2]=-1; t[4][1]=-1;t[4][2]=2; t[5][1]=-2;t[5][2]=1; t[6][1]=1;t[6][2]=-2; t[7][1]=-1;t[7][2]=-2; t[8][1]=-2;t[8][2]=-1; } void main() { int n,i,j; char p; cin>>n; in(); for (i=1;i<=n;i++) { cin>>p; a=int(p)-96; cin>>p; b=int(p)-48; print(); } } #include <stdio.h> int p[8][8]={2,3,4,4,4,4,3,2, 3,4,6,6,6,6,4,3, 4,6,8,8,8,8,6,4, 4,6,8,8,8,8,6,4, 4,6,8,8,8,8,6,4, 4,6,8,8,8,8,6,4, 3,4,6,6,6,6,4,3, 2,3,4,4,4,4,3,2}; void main(void) { int N; scanf("%i\n",&N); for(int i=0;i<N;i++) { char letter,digit; scanf("%c%c\n",&letter,&digit); int il,id; il=letter-'a'+1; id=digit-'0'; printf("%i\n",p[il-1][id-1]); } } #include <iostream> using namespace std; long mz (long xx,long yy) { if ((xx<1)||(xx>8)) return (0); if ((yy<1)||(yy>8)) return (0); return (1); } int main () { long n; char str[100]; long x,y,xx,yy; long i,total; cin>>n; for (i=0;i<n;i++) { cin>>str; total=0; x=(long)(str[0])-96; y=(long)(str[1])-48; xx=x+2; yy=y+1; if (mz(xx,yy)) total++; xx=x-2; yy=y+1; if (mz(xx,yy)) total++; xx=x-2; yy=y-1; if (mz(xx,yy)) total++; xx=x+2; yy=y-1; if (mz(xx,yy)) total++; xx=x+1; yy=y+2; if (mz(xx,yy)) total++; xx=x-1; yy=y+2; if (mz(xx,yy)) total++; xx=x-1; yy=y-2; if (mz(xx,yy)) total++; xx=x+1; yy=y-2; if (mz(xx,yy)) total++; cout<<total<<endl; } return (0); } 这个比较罗嗦的 pls can somebody tell me why i got compilation error on this code #include <stdio.h> #include <stdlib.h> inline int numberOfAttackedFields(int x, int y) { int i = 0; if (x - 1 > 0 && y - 2 > 0) { i++; }
if (x + 1 < 9 && y - 2 > 0) { i++; }
if (x + 2 < 9 && y - 1 > 0) { i++; }
if (x + 2 < 9 && y + 1 < 9) { i++; }
if (x + 1 < 9 && y + 2 < 9) { i++; }
if (x - 1 > 0 && y + 2 < 9) { i++; }
if (x - 2 > 0 && y + 1 < 9) { i++; }
if (x - 2 > 0 && y - 1 > 0) { i++; } return i; } int main(void) { int x, y, n; char input[3]; char firstLetter; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%s", input); input[2] = '\0';
firstLetter = input[0];
//lower case if (firstLetter - 'a' >= 0 && firstLetter - 'a' <= 8) { x = firstLetter - 'a' + 1; } //upper case else { x = firstLetter - 'A' + 1; }
//replace the first letter with 0 input[0] = '0'; y = atoi(input); printf("x=%d y=%d\t%d\n", x, y, numberOfAttackedFields(x, y)); }
return 0; } it compiles with no problems on my MAC. I recieve compilation error on any code I submit! But no problems on my side. (...) int main() { int t; scanf("%d",&t); getchar(); while(t--){ char a[10]; scanf("%s", a); int count = 0; if(a[0]-96-2>0 && a[1]-48-2>0) count+=2; else{ if(a[0]-96-1>0 && a[1]-48-2>0) count+=1; if(a[0]-96-2>0 && a[1]-48-1>0) count+=1; } if(a[0]-96+2<9 && a[1]-48-2>0) count+=2; else{ if(a[0]-96+1<9 && a[1]-48-2>0) count+=1; if(a[0]-96+2<9 && a[1]-48-1>0) count+=1; } if(a[0]-96-2>0 && a[1]-48+2<9) count+=2; else{ if(a[0]-96-1>0 && a[1]-48+2<9) count+=1; if(a[0]-96-2>0 && a[1]-48+1<9) count+=1; } if(a[0]-96+2<9 && a[1]-48+2<9) count+=2; else{ if(a[0]-96+1<9 && a[1]-48+2<9) count+=1; if(a[0]-96+2<9 && a[1]-48+1<9) count+=1; } cout<<count<<endl; } return 0; } program Project1; {$APPTYPE CONSOLE} uses SysUtils; var i,j:integer; kolvo, x,y,otvet: longint; koord:string; alpha:string; begin {$IFNDEF ONLINE_JUDGE} assign(input, 'input.txt'); reset(input); assign(output, 'output.txt'); rewrite(output); {$ENDIF} alpha:='abcdefgh'; readln(kolvo); //ff for i:=1 to kolvo do begin otvet:=0; readln(koord); for j:=1 to 8 do if koord[1]=alpha[j] then y:=j; x:=strtoint(koord[2]); if ((x-2)>=1) and ((y-1)>=1) then otvet:=otvet+1; if ((x-1)>=1) and ((y-2)>=1) then otvet:=otvet+1; if ((x-2)>=1) and ((y+1)<=8) then otvet:=otvet+1; if ((x-1)>=1) and ((y+2)<=8) then otvet:=otvet+1; if ((x+2)<=8) and ((y-1)>=1) then otvet:=otvet+1; if ((x+1)<=8) and ((y-2)>=1) then otvet:=otvet+1; if ((x+2)<=8) and ((y+1)<=8) then otvet:=otvet+1; if ((x+1)<=8) and ((y+2)<=8) then otvet:=otvet+1; writeln(otvet); end; {$IFNDEF ONLINE_JUDGE} close(input); close(output); {$ENDIF} end. #include <iostream> #include <stdio.h> #include <vector> using namespace std; class Place { public: char x; int y;
bool isOnboard() { if (x < 'a' || x > 'h' || y < 1 || y > 8) return false; return true; }
Place(char x, int y) { this->x = x; this->y = y; }
}; int main(int argc, const char * argv[]) { int N; cin >> N;
vector<Place> places;
for (int i = 0; i < N; i++) { char x; int y; cin.get(x);
if (x == '\n') { i--; continue; }
cin >> y;
Place place (x, y); places.push_back(place);
}
for (int i = 0; i < N; i++) { Place place = places[i]; int moves = 0;
//left 2 up 1 place.x -= 2; place.y -= 1; moves += place.isOnboard();
//left 2 down 1 place.y += 2; moves += place.isOnboard();
//right 2 down 1 place.x += 4; moves += place.isOnboard(); //right 2 up 1 place.y -= 2; moves += place.isOnboard(); //right 1 up 2 place.x -= 1; place.y -= 1; moves += place.isOnboard(); //left 1 up 2 place.x -= 2; moves += place.isOnboard(); //left 1 down 2 place.y += 4; moves += place.isOnboard(); //right 1 down 2 place.x += 2; moves += place.isOnboard();
cout << moves << endl;
}
} Edited by author 24.01.2014 20:05 This is simply a bruteforce solution, but it is pretty clear though. ;) #include <iostream> using namespace std; int check(int r,int c) { int counter=0; if((r-1)>=0&&(c-2)>=0) counter++; if((r-1)>=0&&(c+2)<=7) counter++; if((r+1)<=7&&(c-2)>=0) counter++; if((r+1)<=7&&(c+2)<=7) counter++; if((c-1)>=0&&(r+2)<=7) counter++; if((c-1)>=0&&(r-2)>=0) counter++; if((c+1)<=7&&(r-2)>=0) counter++; if((c+1)<=7&&(r+2)<=7) counter++; return counter; } int main() { char v; int h,i,vint,n; cin >> n; for(i=0;i<n;i++) { cin >> v>>h; h--; vint=int(v)-97; cout<<check(h,vint)<<endl; } } |
|