Общий форумplease, help me... my code: #include <iostream> using namespace std; int main() { int n,m[16],k; char c[48][20],v[16][20],ch[3][20]; cin>>n; for(int i=0;i<n*3;i++) cin>>c[i]; for(int i=0;i<n;i++) { cin>>k; m[i]=k; } k=(m[0]-1)*3; if((strcmp(c[k],c[k+1])<=0)&&(strcmp(c[k],c[k+2])<=0)){strcpy(v[0],c[k]);} if((strcmp(c[k+1],c[k])<=0)&&(strcmp(c[k+1],c[k+2])<=0)){strcpy(v[0],c[k+1]);} if((strcmp(c[k+1],c[k])<=0)&&(strcmp(c[k+1],c[k+2])<=0)){strcpy(v[0],c[k+1]);} for(int i=1;i<n;i++) { k=(m[i]-1)*3; if((strcmp(c[k],c[k+1])<=0)&&(strcmp(c[k],c[k+2])<=0)) { strcpy(ch[0],c[k]); if(strcmp(c[k+1],c[k+2])<=0) { strcpy(ch[1],c[k+1]); strcpy(ch[2],c[k+2]); } else { strcpy(ch[2],c[k+1]); strcpy(ch[1],c[k+2]); } }
if((strcmp(c[k+1],c[k])<=0)&&(strcmp(c[k+1],c[k+2])<=0)) { strcpy(ch[0],c[k+1]); if(strcmp(c[k],c[k+2])<=0) { strcpy(ch[1],c[k]); strcpy(ch[2],c[k+2]); } else { strcpy(ch[2],c[k]); strcpy(ch[1],c[k+2]); } }
if((strcmp(c[k+2],c[k])<=0)&&(strcmp(c[k+2],c[k+1])<=0)) { strcpy(ch[0],c[k+2]); if(strcmp(c[k],c[k+1])<=0) { strcpy(ch[1],c[k]); strcpy(ch[2],c[k+1]); } else { strcpy(ch[2],c[k]); strcpy(ch[1],c[k+1]); } }
if(strcmp(v[i-1],ch[0])<=0) { strcpy(v[i],ch[0]); } else { if(strcmp(v[i-1],ch[1])<=0) { strcpy(v[i],ch[1]); } else { if(strcmp(v[i-1],ch[2])<=0) { strcpy(v[i],ch[2]); } else { cout<<"IMPOSSIBLE"; return 0; } } } } for(int i=0;i<n;i++) { cout<<v[i]<<endl; } return 0; } Am nevoie e ajutor, va rog io \\warn Edited by author 28.10.2010 14:45 da mah, io is cantaretz, si acuma tre sa fac probleme de pe timus. dami si mie te rog io fain, raspunsu sau un indiciu Ce warn o luat fratzica =)) Tags: dynamic programming But most solution of the problem use a greedy algo On the 11-(10-1)th of Febr(10-2)uary, 2006(10-3) the conte(10-4)st "Timus (10-5)Top Coders(10-6): First Ch(10-7)allenge" i(10-8)s held! The exemple of this problem is wrong,isn't it? Example is correct: On the 11-<1>th of February<2>, 2006 the <3>contest "T<4>imus Top Coders<5>: First Ch<6>allenge" i<7>s held!<8> you are very very very bad man, the correct answer to example is: On the 11-<1-10>th of February<2-14>, 2006 the<3-10> contest "<4-10>Timus Top Coder<5-15>s: First C<6-10>hallenge" <7-10>is held!<8> in your example ", 2006 the " 11 simbols!!! after your explain I think that spaces in begin of sms must delete and I always have WA4! Sorry , have found bug. Edited by author 24.04.2009 03:03 Anybody, wright test 10, please... I can't understand it, either. Edited by author 25.05.2010 08:31 hi,standard input has keyboard. and standard output has monitor. I have WA on the test 25. Who can help me? I have the tests. If you want them , post your mail adress. This is mine: charles8827@163.com Thank you very much. Gheorghe Stefan I got WA on test 15.. Please post the tests to me. Thank you very much. My e-mail : happy123456@hotmail.com Edited by author 18.05.2004 16:47 I find the tests. And I find my mistake. I got AC . :) Edited by author 18.05.2004 16:57 Here is my e-mail:sanguokuang@yahoo.com.cn Please send me the tests.Thenk you! Please give me the tests. My e-mail : alexpopa@shock.ldc.ro I found the tests on the web, I tested my program an it shows the correct answers. Can anybody help me ? Could anyone tell me where I can get the tests?Thank you. My program passes all tests from NEERC, but has WA18 on Timus. I can't find my mistake. :( I Wa on Test 25, I need the Tests. Could you send it to me? Thank you. My E-mail: Skyfish_cdq@hotmail.com I have the tests. If you want them , post your mail adress. I Wa on Test 25. Could you send it to me? Thank you. alvinhuang1105@163.com Just google "NEERC 2001"... Interestingly enough the problem can be solved with simple simulation. Just simulate the process, choosing random directions and random initial positions while you are within the time limit and you will get accepted. I really doubt this is the correct solution, so I was wondering what is the real one? There is very simple O(m) solution - just use your algorithm for solution of previous problem. I've got WA#9. My algo is: first I generate the possible answers in both directions (strating from 1 and n) with algorithm from the previous problem, and with KMP I'm searching the input array for match, also I added special cases for 2 (1 1 and 2 2) and for 3 (2 2). Edited by author 20.10.2010 04:44 To KALO: Try this test 5 10 1 2 3 4 5 1 2 3 4 5 To KALO: Try this test 5 10 1 2 3 4 5 1 2 3 4 5 If N is odd = then sequence are 1..N 1..N 2..N-1 N-1 else the sequence is 2..N-1 N-1.. 2 I'm right? Edited by author 20.10.2010 17:04I don't understand you. As I know, jury's solution don't use misterious knowledges about any sequences. =) O(m) solution doesn't use them as well =) No, I was talking about general logic of my algorithm. Of course, it is incorrect to search for some predefined sequence in the answer. For example, for m=5 general algorithm gives sequence like 1 2 3 4 5 1 2 3 4 (or something like that), but possible answer is 2 2 4 4 4 4 3 2. if m = 5, 2 2 4 4 4 4 3 2 can't be the answer imagine original is on 4th pedestal you touch 2 orig move 4 -> 3 you touch 2 orig move 3 -> 2 you touch 4 orig move 2 -> 3 you touch 4 orig move 3 -> 2 you touch 4 orig move 2 -> 3 you touch 4 orig move 3 -> 2 you touch 3 orig move 2 -> 3 you touch 2 orig move 3 -> 4 you didn't catch the orig! if the sequence has 2 * k numbers suquencially you can take only 2 if 2 * k - 1 you can take 1 (I think) example 2 2 2 2 3 3 3 5 6 --> 2 2 3 5 6 Edited by author 20.10.2010 22:39 Idea: Game of two person and bacward analysis from the end Example: 3 3 1 2 3 3: 1,2-win; 3- fail 2:1,3-win(1->2,3->2) 2- fail 1:2-win(2->1)1,3-fail so win:2->1->2 Edited by author 25.10.2010 14:41 I understand ur algo but I think it's O(n*m). Isn't It? Won't it get TL Yes. But pattern of failed states exits and it's maitaining costts O(1) on eaxh of n steps. what if n = 10^5 and m = 10^5 sequence is like this 4 6 4 6 4 6 4 6 4 6 . . . I think at this test the length of failed pattern is 1 all the time and time is O(n, m) again. Or I didn't understand your previous massage rightly? To Alexander Georgiev: now your solution gets wa51. do you happy? :) Edited by author 20.10.2010 16:37 Yep. It is interesting - how many brute force solutions fail after new tests :) Sort of =) NOW I have to write a real solution :) I get WA#1 here is my code #include <cstdlib> #include <iostream> using namespace std; int i, j, n, k, say, a[101]; int main(int argc, char *argv[]) { cin >> n >> k;
for( i = 0; i < n ; i++ ) cin >> a[ i ]; if( n%k != 0) say = n/k + 1; else say = n/k;
for( j = 0; j < say; j++ ){ cout << a[ j ]; i = j + say; while( i < n){
cout <<" "<< a[ i ]; i += say; } if( j < say-1 ) cout << endl; }
return 0; } Output: The width of each column must be 4 symbols; the numbers must be aligned to the right edge and padded with spaces to the required width hi.you have 3 error's 1.you get 1 test case,but question has t test case. you can add while(cin>>n>>k){...} to het t,test case,t>0; 2.you end of ant test case add cout<<endl; 3.to any answer printf(" %3d",a[i]); good luck. Which of these formulas correct for this problem 1. M(A) + M(B) - M(AB) 2. M(A)*M(B/A) Is empty string is a substring of the whole string? Is whole string is a substring of the whole string? You can see example: "aaba": a b aa ab ba aab aba aaba Totaly 8 substrings. So, empty string is not substring. And where is "aaa"? substring != subsequence Where is baa? Where is baa? "baa" is not subsequnce of "aaba" Here's my code. It gets WA11. Algo: the rightmost number of the current subarray[i..j] is a root of a subtree. The left branch includes those and only those numbers which are less than root; right branch - numbers greater than root. So if we swap these branches in our array and process them recursively we'll get the desired answer. Example: 1 7 5 (left br.) 21 22 27 25 20 (right br.) 10 (root) 1 (lb) 7 (rb) 5 (rt) empty (lb) 21 22 27 25 (rb) 20 (rt) 21 22 (lb) 27 (rb) 25 (rt) 21 (lb) empty (rb) 22 (rt) result: 27 21 22 25 20 7 1 5 10 proc "tree" does all the work. del is the delimiter of the branches. I've used the most primitive algo to swap the subarrays to simplify the solution.
program parliament; {$APPTYPE CONSOLE} var n,i:integer; a,t:array[1..100000] of integer; procedure tree(i,j:integer); var q,del:integer; begin if j>=i then begin del:=j-1; while (del>=i) and (a[del]>a[j]) do dec(del); for q:=del+1 to j-1 do t[q+i-del-1]:=a[q]; for q:=i to del do t[q+j-1-del]:=a[q]; for q:=i to j-1 do a[q]:=t[q]; tree(i,j-del-1); tree(j-del,j-1); end; end; begin fillchar(t,sizeof(t),0); read(n); for i:=1 to n do read(a[i]); tree(1,n); for i:=1 to n do write(a[i],' '); end. So, I also have WA11! What is wrong? I cant understand... {$APPTYPE CONSOLE} type Tchild=record a,b:word; end; var n,i:longint; ar:array[1..4000] of word; ch:array[1..4000] of Tchild; procedure write0; var child,oc:longint; begin child:=1; oc:=1; while (ch[child].a<>0)or(ch[child].b<>0) do begin oc:=child; if ch[child].b<>0 then child:=ch[child].b else child:=ch[child].a; end; if ch[oc].a=child then ch[oc].a:=0; if ch[oc].b=child then ch[oc].b:=0; write(ar[child],' '); ar[child]:=0; end; procedure write1; var child,oc:longint; begin child:=1; oc:=1; while (ch[child].a<>0)or(ch[child].b<>0) do begin oc:=child; if ch[child].a<>0 then child:=ch[child].a else child:=ch[child].b; end; if ch[oc].a=child then ch[oc].a:=0; if ch[oc].b=child then ch[oc].b:=0; write(ar[child],' '); ar[child]:=0; end; procedure swap(var a,b:word); var w:word; begin w:=a; a:=b; b:=w; end; procedure getplace(x,i:longint); var old,p,child:longint; begin p:=1; while true do begin if (x>ar[p])and(ch[p].b=0) then begin ch[p].b:=i; exit; end; if (x<ar[p])and(ch[p].a=0) then begin ch[p].a:=i; exit; end; if (x>ar[p]) then begin p:=ch[p].b; continue; end; if (x<ar[p]) then begin p:=ch[p].a; continue; end; end; end; begin fillchar(ch,sizeof(ch),0); readln(n); for i:=1 to n do read(ar[i]); for i:=1 to n div 2 do swap(ar[i],ar[n-i+1]); for i:=2 to n do getplace(ar[i],i); if n mod 2=1 then begin for i:=1 to n do write0; end else begin for i:=n downto 1 do write(ar[i],' '); end; end. The other realization of the same algo is AC. But where is the mistake here? Why WA???????????????? #define clr(x,y) memset(x,y,sizeof(x)) using namespace std; int a[400000]; int a1[400000],a2[400000]; int s[400000]; int n; bool cmp(int x,int y) { return a[x]<a[y]; } int main(void) { freopen("input.in","r",stdin); freopen("output.out","w",stdout); cin >>n; if (n<1)return 0; for (int i=0;i<n;i++) { scanf("%d",&a[i]); } int k1=0,k2=0; for (int i=0;i<n-1;i++) if (a[n-1]>a[i]) { a1[k1++]=i; } else { a2[k2++]=i; } int t=-1; bool f=0; if (k2!=0) { sort(a2,a2+k2,cmp);
for (int i=k2-2;i>=0;i--) { // cout << a[a2[i+1]]<< " " << a[a2[i]]<<endl; if (a2[i+1]<a2[i]) { if (f) { s[++t]=a2[i+1]; while (t>=0)cout << a[s[t--]]<< " "; }else cout << a[a2[i+1]]<< " "; f=0; } else { s[++t]=a2[i+1]; f=1; } }
s[++t]=a2[0]; while (t>=0)cout << a[s[t--]]<< " "; } t=-1; f=0; if (k1!=0) { sort(a1,a1+k1,cmp); for (int i=k1-2;i>=0;i--) { // cout << a[a2[i+1]]<< " " << a[a2[i]]<<endl; if (a1[i+1]<a1[i]) { if (f) { s[++t]=a1[i+1]; while (t>=0)cout << a[s[t--]]<< " "; }else cout << a[a1[i+1]]<< " "; f=0; } else { s[++t]=a1[i+1]; f=1; } }
s[++t]=a1[0]; while (t>=0)cout << a[s[t--]]<< " "; } cout << a[n-1]; return 0; } Edited by author 27.10.2010 15:51 How much testcase there are in the input. i've got wrong answer.but why?all works in 100% but i've got a wrong answer Edited by author 28.09.2010 21:28 hi algorithm to 1001: 1.to all test case(1-n) to have "sqrt(x)" 2.print result for test case n to test case 1. sorry,I dont good write engilish. good luck. InFile - d.in OutFile - d.out 1 second 4 MiB find a number that is more than N and sum of numbers=S. C++ I've got AC already. I had WA on 11th test first, but then i changed the size of char array from 1000 to 1001... That changed ny WA on AC!! Guess, the true size of array is 1001 in 11th test case. Can post my solution... Can you give me some test my program got WA 5 6 3 1 1 5 RB --- ANS: 8.4853 50000 ranked authors (who has at least one AC)! There are a lot of accounts without an accepted solution at all. Edited by author 27.10.2010 01:38 Here is my code: #include <iostream> using namespace std; //long int _wants[200002]; //long int _nums[100001]; long int n; long int *_wants; long int *_nums; int main() { cin>>n; _wants = new long int[2*n]; _nums = new long int[n]; for (long int i=0; i<n; i++) cin>>_wants[i]; for (long int i=0; i<n; i++) { _nums[i]=_wants[i]; _wants[i]-=i+1; _wants[i+n]=_wants[i]-n; } long int _max=_wants[0]; long int _pos=1; long int _count=1; for (long int j=0; j<n; j++) { if (_wants[j]>-n) { _count=1; for (long int i=j+1; i<2*n; i++) { if (_wants[i]==_wants[j]) { _wants[i]=-n; _count++; } } _wants[j]=_count; if (j==0) _max=_wants[j]; else if (_wants[j]>_max) { _max=_wants[j]; _pos=j-(_nums[j])+2; } } } if (_pos<=0) _pos+=n; cout<<_pos<<endl; return 0; } My algo is following: we take the input twice, like this: for "4 1 2 3" - "4 1 2 3 4 1 2 3". For each standing in array of meanings we count arr[i]-i . For students standing in a right way to answer counting gives same results. Then we count a number of each difference in our array of 2*n elements, but only for meanings in left half of arr (and write it to the beginning of the arr). After that we will have the length of the longest sequence and its beginning position. There's no problem to say who must be first. I found out that for n=99999 there's a TL. But why? This algo is enough fast... Edited by author 25.10.2010 13:15 your program do O(n^2) operation (you have two embedded loop) |
|