Show all threads Hide all threads Show all messages Hide all messages | Easy problem | ValenKof | 1140. Swamp Incident | 20 Dec 2021 16:22 | 2 | Just try to replace x, y or z using equation y = x + z (vector form). Count of cells on path is |x| + |y| + |z| + 1. This is brilliant Just try to replace x, y or z using equation y = x + z (vector form). Count of cells on path is |x| + |y| + |z| + 1. | WA6 | ura | 1140. Swamp Incident | 10 Dec 2018 20:32 | 1 | WA6 ura 10 Dec 2018 20:32 | AC on C but Runtime error on C# | Semm | 1140. Swamp Incident | 30 Jul 2016 19:32 | 2 | Hi, I've solved the problem easily on C, but can't solve it on C# (almost the same code), getting Runtime Error on #2. Can someone point out what's wrong in my code? using System; namespace Application { class MainClass { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] pos = new int[3]; for(int i=0; i<n; i++) { string[] s = Console.ReadLine().Split(' '); int ind = s[0][0] - 'X'; pos[ind] += int.Parse(s[1]); }
while(true) { if(pos[0] * pos[2] > 0) { int sign = pos[0] / Math.Abs(pos[0]); int min = Math.Min(Math.Abs(pos[0]), Math.Abs(pos[2])); pos[0] -= sign * min; pos[1] += sign * min; pos[2] -= sign * min; } else if(pos[0] * pos[1] < 0) { int sign = pos[0] / Math.Abs(pos[0]); int min = Math.Min(Math.Abs(pos[0]), Math.Abs(pos[1])); pos[0] -= sign * min; pos[1] += sign * min; pos[2] -= sign * min; } else if(pos[1] * pos[2] < 0) { int sign = pos[2] / Math.Abs(pos[2]); int min = Math.Min(Math.Abs(pos[1]), Math.Abs(pos[2])); pos[0] -= sign * min; pos[1] += sign * min; pos[2] -= sign * min; } else { break; } } int nOfDir = 0; if(pos[0] != 0) nOfDir++; if(pos[1] != 0) nOfDir++; if(pos[2] != 0) nOfDir++; Console.WriteLine(nOfDir); if(pos[0] != 0) Console.WriteLine("X " + (-pos[0]).ToString()); if(pos[1] != 0) Console.WriteLine("Y " + (-pos[1]).ToString()); if(pos[2] != 0) Console.WriteLine("Z " + (-pos[2]).ToString()); } } } To get AC instead of Console.ReadLine() I used Console.In.ReadToEnd().Split(new char[] { ' ', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries) | WA #8 | Vladimir | 1140. Swamp Incident | 24 Feb 2013 23:44 | 2 | WA #8 Vladimir 8 Dec 2012 18:35 Wrong answer 8, give me some tests, please! Написал на С++ и всё заработало. Как? Wrote in C++ and it's work! How? | Some hints for you ! | Phan Hoài Nam (Harvey Nash) | 1140. Swamp Incident | 9 Feb 2011 09:39 | 1 | - Calculate the x y coordinates of the student - Find the X, Y or Z axis nearest to the student (the axis that the student can go on it with least step). - Calculate the number of steps to nearest axis + the number of steps from new place in nearest axis to central cell. Note: On X axis : x = 0 On Y axis : x = y On Z axis : x = -y Least steps to X: x + step * xDir = 0 => step = ? Least steps to Y: x + step * xDir = y + step * yDir => step = ? Least steps to Z: x + step * xDir = - (y + step * yDir) => step = ? Of which: X axis : (xDir, yDir) = (0,2) Y axis : (xDir, yDir) = (1,1) Z axis : (xDir, yDir) = (1,-1) Chúc các bạn may mắn :) Edited by author 09.02.2011 09:40 Edited by author 09.02.2011 09:41 | what's wrong? | Edric Mao | 1140. Swamp Incident | 2 Sep 2010 16:39 | 1 | program ural; uses math; var s:array['X'..'Z']of integer; c:char; d,n,i:integer; begin readln(n); for i:=1 to n do begin read(c); readln(d); s[c]:=s[c]+d; end; if(s['X']>0)and(s['Z']>0)then begin d:=min(s['X'],s['Z']); inc(s['Y'],d); dec(s['X'],d); dec(s['Z'],d); end else if(s['X']<0)and(s['Z']<0)then begin d:=max(s['X'],s['Z']); inc(s['Y'],d); dec(s['X'],d); dec(s['Z'],d); end; if(s['X']>0)and(s['Y']<0)then begin d:=max(-s['X'],s['Y']); inc(s['Z'],d); inc(s['X'],d); dec(s['Y'],d); end else if(s['X']<0)and(s['Y']>0)then begin d:=min(-s['X'],s['Y']); inc(s['Z'],d); inc(s['X'],d); dec(s['Y'],d); end; if(s['Z']>0)and(s['Y']<0)then begin d:=max(-s['Z'],s['Y']); inc(s['X'],d); inc(s['Z'],d); dec(s['Y'],d); end else if(s['Z']<0)and(s['Y']>0)then begin d:=min(-s['Z'],s['Y']); inc(s['X'],d); inc(s['Z'],d); dec(s['Y'],d); end; writeln(abs(s['X'])+abs(s['Y'])+abs(s['Z'])); if s['X']<>0 then writeln('X ',-s['X']); if s['Y']<>0 then writeln('Y ',-s['Y']); if s['Z']<>0 then writeln('Z ',-s['Z']); end. | It just CAN't be made faster!!! | Tbilisi SU: Andrew Lutsenko | 1140. Swamp Incident | 27 Jan 2009 14:09 | 3 | I have only two coordinates on a plane, and just read input. Nothing more and my prog works 0,046 sec. But in statistics there are AC's in 0,001 sec. I wonder how can it be??? Quicker reading. For example, scanf is quicker than cin. And gets + atoi is better than scanf("%d") Edited by author 01.09.2006 11:42 Replacing scanf->gets,atoi seems not to be enough | This problem is really hard to understand! | Nickolas Kakà | 1140. Swamp Incident | 7 Jun 2008 21:18 | 1 | It really hard to understand the meaning of the description of this problem!It took me an hour and more! | Please help! | Helmdall | 1140. Swamp Incident | 7 Jan 2008 16:03 | 1 | I think the way to solve this prob is convert to Dekart coordinate-system. Below is my solution, I got WA at test #2 >.<. var nowX: longint; nowY: longint; {--------------------------------------------------------} procedure moveX(lengths: longint); begin nowX:= nowX + lengths; end; {--------------------------------------------------------} procedure moveY(lengths: longint); begin nowY:= nowY + lengths; end; {--------------------------------------------------------} procedure move(section: integer; direction: char; lengths: longint); var tmp: longint; begin case direction of 'X': begin case section of 1: if (nowX + lengths < 0) then begin tmp:= nowX; moveX(-nowX); move(2, 'X', lengths + tmp); end else moveX(lengths); 4: if (nowX + lengths < 0) then begin tmp:= nowX; moveX(-nowX); move(2, 'X', lengths + tmp); end else moveX(lengths); 2: if (nowX + lengths > 0) then begin tmp:= nowX; move(2, 'X', -nowX); move(1, 'X', lengths + tmp); end else begin moveX(lengths); moveY(lengths); end; 3: if (nowX + lengths > 0) then begin tmp:= nowX; move(3, 'X', -nowX); move(4, 'X', lengths + tmp); end else begin moveX(lengths); moveY(lengths); end; end; end; 'Y': begin moveY(lengths); end; 'Z': begin case section of 1: if (nowX - lengths < 0) then begin tmp:= nowX; move(1, 'Z', nowX); move(2, 'Z', lengths - tmp); end else begin moveX(-lengths); moveY(lengths); end; 4: if (nowY + lengths > 0) then begin tmp:= nowY; move(4, 'Z', -nowY); move(1, 'Z', lengths + tmp); end else begin if (nowX - lengths < 0) then begin tmp:= nowX; move(4, 'Z', nowX); move(3, 'Z', lengths - tmp); end else begin moveX(-lengths); moveY(lengths); end; end; 2: if (nowX - lengths > 0) then begin tmp:= nowX; move(2, 'Z', nowX); move(1, 'Z', lengths - tmp); end else moveX(-lengths); 3: if (nowX - lengths > 0) then begin tmp:= nowX; move(3, 'Z', nowX); move(4, 'Z', lengths - tmp); end else moveX(-lengths); end; end; end; end; {--------------------------------------------------------} function getNowSection: integer; begin if (nowX < 0) then begin if (nowY < 0) then exit(3) else exit(2); end else begin if (nowY < 0) then exit(4) else exit(1); end; end; {--------------------------------------------------------} procedure readInput; var i: integer; n: integer; dir: char; len: longint; begin readln(n); for i:= 1 to n do begin readln(dir, len); move(getNowSection, dir, len); end; end; {--------------------------------------------------------} procedure writeOutput; begin if (nowX = 0) and (nowY = 0) then begin write(0); exit; end; if (nowX = 0) then begin writeln(1); write('Y ', -nowY); exit; end; if (nowY = 0) then begin writeln(1); if (nowX > 0) then write('X ', -nowX) else write('Z ', nowX); exit; end; writeln(2); case getNowSection of 1: begin writeln('X ', -nowX); write('Y ', -nowY); end; 2: begin writeln('Z ', nowX); write('Y ', -nowY); end; 3: begin if (nowX = nowY) then write('X ', -nowY) else if (nowX < nowY) then begin writeln('X ', -nowY); move(3, 'X', -nowY); writeln('Z ', nowX); end else begin writeln('X ', -nowX); move(3, 'X', -nowX); write('Y ', -nowY); end; end; 4: begin if (nowX = abs(nowY)) then write('Z ', nowX) else if (nowX < abs(nowY)) then begin writeln('Z ', nowX); move(4, 'Z', nowX); write('Y ', -nowY); end else begin writeln('Z ', -nowY); move(4, 'Z', nowY); write('X ', -nowX); end; end; end; end; {--------------------------------------------------------} begin readInput; writeOutput; end. | Please help me with my program | dunno1 | 1140. Swamp Incident | 17 Dec 2007 00:24 | 1 | I just can't find where's mistake - i always get WA at test #1: #include<iostream> #include<string> #include<vector> #include<cmath> #include<cstdio> #include<cstdlib> #include<algorithm> #include<set> #define REP(i,n) for(int i=0;i<n;i++) #define REPD(i,n) for(int i=n;i>-1;i--) #define FOR(i,j,k) for(int i=j;i<k;i++) #define FORD(i,j,k) for(int i=j;i>k;i--) #define PB push_back using namespace std; int main() { int n; cin>>n;
int X=0,Y=0,Z=0;
REP(i,n) { char a;int p; cin>>a;cin>>p; if(a=='X') X+=p; else if(a=='Y') Y+=p; else Z+=p; } X+=Y;Z+=Y;
if(X==0&&Z==0) cout<<"0"<<endl;
else if(X==0) { cout<<"1"<<endl;cout<<"Z: "<<(-1)*Z<<endl;} else if(Z==0){ cout<<"1"<<endl; cout<<"X: "<<(-1)*X<<endl;} else if(abs(X)==abs(Z)) { cout<<"1"<<endl;cout<<"Y: "<<(-1)*X<<endl;} else if(X>0&&Z>0) { int minimum=X+Z; int a=min(X,Z);
if(X<Z) { cout<<"2"<<endl; cout<<"Y: "<<(-1)*a<<endl; cout<<"Z: "<<(-1)*(Z-a)<<endl; } else { cout<<"2"<<endl; cout<<"X: "<<(-1)*(X-a)<<endl; cout<<"Y: "<<(-1)*a<<endl; } } else if(X<0&&Z<0) { int minimum=X+Z; int a=abs(max(X,Z)); if(X<Z) { cout<<"2"<<endl; cout<<"X: "<<(-1)*(X+a)<<endl; cout<<"Y: "<<a<<endl; } else { cout<<"2"<<endl; cout<<"Y: "<<a<<endl; cout<<"Z: "<<(-1)*(Z+a)<<endl; }
} else { cout<<"2"<<endl; cout<<"X: "<<(-1)*X<<endl; cout<<"Z: "<<(-1)*Z<<endl; } int p;cin>>p; } | I can't understand the sample test. | Neumann | 1140. Swamp Incident | 5 Feb 2005 20:15 | 2 | According to the problem describe,the text's answer should be: y -2 Z -2 and my AC program produce this answer. Is there something wrong? | Some hint(s) | Pasha | 1140. Swamp Incident | 5 Aug 2004 13:19 | 1 | Hello, world! I've solved this problem using representation triangle coordinates as ortogonal Dekart coordinates. Especially pay attention at the test 3 X 45 Z 45 Y -45 The answer must be ZERO: 0 | Please tell me what 's wrong with this program, Thank you! | ECUST Multistar | 1140. Swamp Incident | 18 Jul 2004 00:55 | 3 | var x,y,z:integer; n,i,j:integer; na,nx,ny,nz,nj:integer; c:char; begin x:=0;y:=0;z:=0; readln(n); for i:=1 to n do begin readln(c,j); case upcase(c) of 'X':inc(x,j); 'Y':inc(y,j); 'Z':inc(z,j); end; end; nx:=0;ny:=y+x;nz:=z-x;nj:=abs(nx)+abs(ny)+abs(nz); if (ny=0) or (nz=0) then na:=1 else na:=2; x:=nx+ny;y:=0;z:=nz+ny;j:=abs(x)+abs(y)+abs(z); if (x=0) or (z=0) then n:=1 else n:=2; if nj>j then begin na:=n;nx:=x;ny:=y;nz:=z;nj:=j; end; x:=nx-nz;y:=ny+nz;z:=0;j:=abs(x)+abs(y)+abs(z); if (x=0) or (y=0) then n:=1 else n:=2; if nj>j then begin na:=n;nx:=x;ny:=y;nz:=z;nj:=j; end; writeln(na); if nx<>0 then writeln('X ',-nx); if ny<>0 then writeln('Y ',-ny); if nz<>0 then writeln('Z ',-nz); end. Your test is incorrect because n>0! Try this test: 3 X 1 Z 1 Y -1 Correct output : 0 Your output : 1 | What does the problem mean??? | tbtbtb | 1140. Swamp Incident | 29 Apr 2004 11:15 | 1 | Edited by author 10.07.2004 14:27 | weird,my program keeps "running",but it doesn't get TLE,please help me,tell me what's the matter | dynamic(Ying Wang) | 1140. Swamp Incident | 4 Feb 2003 12:08 | 3 | i submit my program,but the status is always "running" now i have no idea about it,maybe something is wrong with the judge? here is my program: #include <stdio.h> #include <string.h> #include <math.h> #include <ctype.h> int x=0,y=0,z=0; void eliminate_x(){ y+=x,z-=x,x=0; } void eliminate_y(){ x+=y,z+=y,y=0; } void eliminate_z(){ x-=z,y+=z,z=0; } int main() { int i,n,step,type=0,min,m; char c; //freopen("test.in","r",stdin); scanf("%d",&n); for(i=0;i<n;i++){ c=0; while(!isalpha(c)) c=getchar(); scanf("%d",&step); if (c=='X') x+=step; else if (c=='Y') y+=step; else if (c=='Z') x-=step,y+=step; } min=abs(x)+abs(y); eliminate_x(); if (abs(y)+abs(z)<min) min=abs(y)+abs(z),type=1; eliminate_y(); if (abs(x)+abs(z)<min) min=abs(x)+abs(z),type=2; m=0; if (type==0){ eliminate_z(); if (!x) m++; if (!y) m++; printf("%d\n",m); if (x) printf("X %d\n",-x); if (y) printf("Y %d\n",-y); }else if (type==1){ eliminate_x(); if (!y) m++; if (!z) m++; printf("%d\n",m); if (y) printf("Y %d\n",-y); if (z) printf("Z %d\n",-z); }else{ if (!x) m++; if (!z) m++; printf("%d\n",m); if (x) printf("X %d\n",-x); if (z) printf("Z %d\n",-z); } return 0; } if wait a little more (at last 1day) you will find your result. don`t submit it again... Yours Aidin Yeah... And my program keep running. I submit it before 12 hours !!!! :)))) How many tests there is for this problem ? :)) |
|
|