Общий форумIn what position brick can fall through the hole? Why program like follows doesn't work properly? var a, b, c, d, e: real; begin readln(a, b, c, d, e); if (a<=d)and(b<=e)or (a<=e)and(b<=d)or (a<=d)and(c<=e)or (a<=e)and(c<=d)or (b<=d)and(c<=e)or (b<=e)and(c<=d) then writeln('YES') else writeln('NO') end. We can rotate bricks! Example 1x10x10 we can push to 9x9 Thanks for Your hint! I've got AC now. Edited by author 28.07.2004 11:31 Thanks for Your hint! I've got AC now. Edited by author 28.07.2004 11:31 Thanks for Your hint! I've got AC now. Edited by author 28.07.2004 11:31 Haha, I wrote the exactly same code... Please, tell me some tests to check my program... I have WA#2 Problem statement is wrong. Two types of walls should be exchanged. I'm change type of walls, bu I still have WA#2. Could you give me some test? Had WA2, because i've read walls, but completely forgot to take them into account. Haha... Give me test#12, please. I tried all tests in the discussions, but still WA12 Edited by author 27.01.2014 14:42 0e2000000000 10 0e4000000000 10 One more test 100e- 1 Edited by author 28.11.2015 11:54 Edited by author 28.11.2015 11:54 Решая задачу обыватель мог столкнуться с проблемой того,как вводить данные. Данные водятся потоком, поэтому мы не знаем какое количество чисел войдут на проверку, для этого нам нужно использовать следующую конструкцию: var r:real; .. Begin while not seekeof do Begin read(r); .. End; .. End. while not seekeof do - пока не конце файла, то делай то то. пропуская пробелы и переходы на новую строчку. Но так как отсутствует файлы, то он ждёт конец потока вводимых с экрана данных. Для решения просто вставляем эту конструкцию, дополняя кодом и всё. http://acm.timus.ru/help.aspx?topic=pascal Edited by author 28.11.2015 11:30here is my code if someone can help me, thanks you and greetings. import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Scanner; public class P1100 { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); int [] vec=new int[n*2]; for(int i=0;i<n*2;i++)vec[i]=in.nextInt(); int [] aux=new int[n]; int mayor=0,menor=100; for(int i=1;i<n*2;i=i+2){ if(menor>vec[i]){ menor=vec[i]; } if(mayor<vec[i]){ mayor=vec[i]; } } int sig=-1; for(int i=0;i<n;i++){ for(int j=1;j<n*2;j=j+2){ if(mayor==vec[j] && vec[j]!=-1 ){ System.out.printf(" %d %d",vec[j-1],vec[j]); vec[j]=-1;
} if(sig<mayor && sig < vec[j] && vec[j]!=-1){ sig=vec[j]; } } mayor=sig; sig=-1; } out.flush();
} } Your solution contains 2 nested loops with range [0..n) each. So you have n^2 complexity. Of course you have TLE.
You should better load input into array of structures (with fields Id, Score), sort array by score field in decreasing order and print it. * "Collections.sort" is stable so you can just use it. im trying now with a arrayList of a node(int ele,int pos), but i dont know how no order that, can you help me? Hi. Is O(N^2) solution good for this problem? I got TL on 8th test. Should I reduce constant in O() or should I find N*logN solution? It's strange that 25M operations take over 2 seconds. Ofc no; the max N is 10^5, so N^2 would be 10^10; thats about 50 seconds to do such number of operations on a normal PC Yes. I thought it is 10^4. I was neglectful. N^2 is almost never acceptable if N exceeds ~4000-5000. I attempted to think a bit at this task... as far as i understood, for flowers with a certain dryness X, let us assume that the leftmost flower with such dryness is X1, the rightmost is X2, Kirill's position is Y. Cases like Y...X1...X2 and X1...X2...Y are easy, Kirill needs to go to the rightmost and to the leftmost flower respectively, but in case of X1...Y...X2 it gets a bit harder. At first, i assumed that we should just go first to the side that we're closer to, but then, i found out a counter test for that: 19 2 9 9 9 9 9 9 9 1 9 9 9 9 9 9 2 3 4 5 Initial path to the right 2, through 6 nines, is shorter than to the left 2, through 7 nines, but eventually this turns out to be a bad decision, since we have to go all the way to the right again. So probably, we should somehow take a group of flowers with next closest dryness into consideration. I'll try to think of it some more when i'm not lazy... Hello! I solved this problem O(N*logN). Idea=Sort+Dp[i,x],where x=the most Right and the most Left . Edited by author 05.11.2015 18:28 ... Edited by author 07.11.2015 13:32 19 2 9 9 9 9 9 9 9 1 9 9 9 9 9 9 2 3 4 5 70, btw for java AC long for path[] is enough (BigInteger works slower few milliseconds) I use Python 3.5 Is it right that it's prohibited to import function gcd from library math? But it's allowed to import this function from library fractions Edited by author 27.11.2015 02:04 If there is three equal points than perimeter equals zero? Something strange: if three points with equal coordinates than output zero. -> WA6 if four points with equal coordinates than output zero. -> AC This made me crazy. Can somebody clarify? I have the same trouble. Maybe something wrong with test or checker? I know i am stupid but help me to understand this formula! n*(n+1)/2*(n+2) Edited by author 02.11.2013 03:06 Edited by author 02.11.2013 03:12 This formula is equivalent to the this sum: sum(i=0 -> N) sum(j=i -> N) (i + j) Edited by author 27.11.2015 01:21 // del got AC Edited by author 26.11.2015 22:07 Edited by author 27.03.2016 21:21 here is my code if someone can help me, thanks you and greetings. import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Scanner; public class P1100 { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); int [] vec=new int[n*2]; for(int i=0;i<n*2;i++)vec[i]=in.nextInt(); int [] aux=new int[n]; int mayor=0,menor=100; for(int i=1;i<n*2;i=i+2){ if(menor>vec[i]){ menor=vec[i]; } if(mayor<vec[i]){ mayor=vec[i]; } } int sig=-1; for(int i=0;i<n;i++){ for(int j=1;j<n*2;j=j+2){ if(mayor==vec[j] && vec[j]!=-1 ){ System.out.printf(" %d %d",vec[j-1],vec[j]); vec[j]=-1;
} if(sig<mayor && sig < vec[j] && vec[j]!=-1){ sig=vec[j]; } } mayor=sig; sig=-1; } out.flush();
} } import java.io.PrintWriter; import java.util.Scanner; public class P1581 { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); int [] vec=new int[n]; for(int i=0;i<n;i++)vec[i]=in.nextInt(); int cont=0,num; num=vec[0]; for(int i=0;i<n;i++){ if(vec[i]==num){ cont=cont+1; } if(vec[i]!=num || i+1==n){ if(i+1!=n){ System.out.printf("%d %d ",cont,num); }else{ System.out.printf("%d %d",cont,num); } num=vec[i]; cont=1; }
} out.flush(); } } ---- THANKS YOU, GREETINGS. Edited by author 26.11.2015 05:45 nub qlo int cont=0,num; num=vec[0]; for(int i=0;i<n;i++){ if(vec[i]==num){ cont=cont+1; } if(vec[i]!=num ){ System.out.printf("%d %d ",cont,num); num=vec[i]; cont=1; } } System.out.printf("%d %d",cont,num); import java.util.*; public class timusTeam { public static void main(String [] args) { int i=0; Scanner in=new Scanner(System.in); int n=in.nextInt();
if(n>1000 || n<1) return;
int arr[]=new int[n]; for(i=0;i<n;i++) { arr[i]=in.nextInt(); if(arr[i]>10 || arr[i]<0) return; }
int a; int sum=0;
i=0; while(i<n) { a=arr[i]; for(int k=0;k<n;k++) if(arr[k]==a) { sum++; i++; } System.out.print(sum +" " +a +" "); sum=0; }
} } im frustrated :( Help me please Edited by author 05.06.2012 16:59 Edited by author 05.06.2012 18:21 6 1 1 2 1 1 1 5 1 5 1 BUILD SUCCESSFUL (total time: 6 seconds) answer -> 2 1 1 2 3 1 BUILD SUCCESSFUL (total time: 4 seconds) You 're telling the amount of x number on the table, read again the problem, greetings. Edited by author 26.11.2015 05:52 It`s wrong on 32 test. I can`t understand the problem. I used bin search. const n0=10000; type u = array[1..n0] of integer; var a:u; b:u; c:u; n,i,k,l,m,j,q,t:integer; function bin_search(s,n:integer; var mas:u):integer; var ib,im,i1:integer; begin i1:=1; ib:=n; while i1<=ib do begin im:=i1+(ib-i1) div 2; if mas[im] = s then begin bin_search:=s; break; end else if mas[im] < s then i1:=im+1 else ib:=im-1; end; if i1>ib then bin_search:=-1; end; begin readln(n); for i:=1 to n do read(a[i]); readln(k); for l:=1 to k do read(b[l]); readln(m); for j:=1 to m do read(c[j]);
for t:=1 to m do begin if bin_search(c[t],m,b)<>-1 then if bin_search(c[t],m,a)<>-1 then q:=q+1; end; writeln(q); end. Edited by author 25.11.2015 10:20 Could someone give me some tests on test10? var n:integer; begin writeln(n); readln(n); case n of 1..4:begin writeln('few'); end; 5..9: begin writeln('several'); end; 10..19: begin writeln('pack'); end; 20..49: begin writeln('lots'); end; 50..99: begin writeln('horde'); end; 100..249: begin writeln('throng'); end; 250..499: begin writeln('swarm'); end; 500..999: begin writeln('zounds'); end; 1000..2000:begin writeln('legion'); end; end; end. Edited by author 24.11.2015 23:33 can someone help me?, im trying search the error but i dont found nothing, greetings.. import java.io.PrintWriter; import java.util.Scanner; public class P{ public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out= new PrintWriter(System.out); int current=1,cont=0;
int n=in.nextInt(); in.nextLine(); for(int i=0;i<n;i++){ String lec; lec=in.nextLine();
if(lec.equals("Aurora") || lec.equals("Alice") ||lec.equals("Ariel") ||lec.equals("Phil")||lec.equals("Peter")||lec.equals("Olaf")||lec.equals("Phoebus")||lec.equals("Ralph")||lec.equals("Robin") ){ if(current==2){ cont=cont+1; } if(current==3){ cont=cont+2; } current=1; } if(lec.equals("Bambi") || lec.equals("Belle") ||lec.equals("Bolt") ||lec.equals("Mulan")||lec.equals("Mowglin")||lec.equals("Mickey")||lec.equals("Silver")||lec.equals("Simba")||lec.equals("Stitch")){ if(current!=2){ cont=cont+1; } current=2; } if(lec.equals("Dumbo") || lec.equals("Genie") ||lec.equals("Jiminy") ||lec.equals("Kuzko")||lec.equals("Kida")||lec.equals("Kenai")||lec.equals("Tarzan")||lec.equals("Tiana")||lec.equals("Winnie")){ if(current==2){ cont=cont+1; } if(current==1){ cont=cont+2; } current=3; } }
System.out.print(cont);
out.flush(); } } solved, just a error on lec.equals("Mowglin") to lec.equals("Mowgli") my bad can someone tell me what is test #5??? 5 test 1 or 2 - A or D Edited by author 24.11.2015 21:12 |
|