Common Board// 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 Input: abcd\" \endinput Output: abcd\" \endinput Build a data-structure which allows O(1) test that s[from..to] is a palindrome. The structure is a 2 x s.size() array: even/odd length times possible center point. typedef vector<int> V; string s(4001, ' '); int n; V mpl[2]; // maximum palindrome length around i (even and odd lengths) inline bool is_polindrome(int from, int to){ assert(0 <= from and from < to and to <= n); int eo = (to - from) % 2, c = (from + to) / 2; return mpl[eo][c] >= c - from; } One can think like that: Let a(k) be the amount of palindromes in [0,k]. Then we have recursion: a(k)=MIN{ 1 if [0,k] is pm , MIN (from i = 0 to k -1) OF a(i) + 1 if [i,k] is pm} { 0 else a(i) + k-i else } I consider ASK to be absolutely right concerning data structure He proposed.
Considering each character as a pivot, expand on both sides to find the length of both even and odd length palindromes centered at the pivot character under consideration and store the length in the 2 arrays (odd & even). Time complexity for this step is O(n^2) maybe it will be useful (or at least interesting) for somebody. at first i tried to make simple DP with O(n^3). i tried in java (and i received TLE in 32th test). after that i tried to realize greed algorithm and understood that this idea is wrong (simple antigreed test is: "abzzbbbzza") aand finally i've made O(n^2) DP. little hint: try to precalc d[l][r]: d[l][r] = true, s[l..r] - palindrom d[l][r] = false, s[l..r] - not palindrom whats the ans for 'abzzbbbzza'? i didn't get it how it will become n^2 because for l=1 to l=n is one loop and for r=l to r=n is inside loop and for checking it is palindrome is another loop so i don't get how it will be n^2 can you please explain me i am very confused here please help me [n ,k] = [int(x) for x in input().split()] if n >= k: ans = 2 * n // k if 2*n%k > 0: ans += 1 print(ans) else: print(2) and [n ,k] = [int(x) for x in input().split()] if n >= k: ans = 2 * n // k if 2*n%k > 1: ans += 1 print(ans) else: print(2) Both is accepted. But second is worng. Need test: 5 3 Can you tell me why I always WA #1? Beacause I have tested all those samples in the board, and I pass them all... OK...I have got it...in Ural...in C...You must write like boolflag == 1...You can not write like boolflag,which works in my computer... aaaabaaa correct answer is 2 a aaabaaa your example is very good ! hello. please tell me about test 10. where can i found it. thank you. 1e-9 in this problem is OK. Edited by author 29.08.2016 21:00 Edited by author 21.11.2015 16:12 |
|