Common Board#include <iostream> #include <algorithm> using namespace std; int main() { int n, a; cin >> n >> a; if (n == 1) cout << 0 << endl; else { int S = n - 1; //int S = n; for (int i = 1; i <= n; i++) { S = S - min(a, i); if (S <= 0) { cout << i << endl; break; } } } } can anybody give me some tests? I've seen few people got AC in 0.015 seconds, but how? I used binary search and each iteration's left border started from the last found number, but not from the beginning of array and got 0.031 seconds. binary search gives n*log^2(n) and its possible to solve this in 3*n if you walk the array with least number on each step and wait until all 3 pointed are same to increase count; I have 0.031 too but i`m sure it is possible to optimize my code (e.g. i`ve placed too many checkers if the array is fully passed) int main() { int ma=0,mb=0,mc=0,an,bn,cn,a[4000],b[4000],c[4000],sum=0; scanf("%d",&an); for(int i=0;i<an;++i) scanf("%d",&a[i]); scanf("%d",&bn); for(int i=0;i<bn;++i) scanf("%d",&b[i]); scanf("%d",&cn); for(int i=0;i<cn;++i) scanf("%d",&c[i]); do { while ((a[ma]==b[mb])&&(b[mb]==c[mc])) { ++sum; ++ma; ++mb; ++mc; if((ma>=an)||(mb>=bn)||(mc>=cn)) break; } if((ma>=an)||(mb>=bn)||(mc>=cn)) break; if(a[ma]==min(min(b[mb],c[mc]),a[ma])) ++ma; else if(b[mb]==min(min(b[mb],c[mc]),a[ma])) ++mb; else if(c[mc]==min(min(b[mb],c[mc]),a[ma])) ++mc; if((ma>=an)||(mb>=bn)||(mc>=cn)) break; } while(1); printf("%d", sum); return 0; } You use Python. There is many useful functions))) My program took only 4 lines))) var a:integer; b:integer; va:integer; vb:integer; ea:integer; eb:integer; ra:integer; rb:integer; boxa:integer; boxb:integer; begin readln(a,b); readln(va,vb);
boxb:=b-(va-a); rb:=b-boxb; readln(ea,eb); boxa:=va-(eb-vb);
writeln(a-boxa,' ',b-boxb);
end. /* My program got WA on test 11!!! What's wrong with my code? Anyone can help me!!! */ #include <map> #include <set> #include <ctime> #include <cmath> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <string> #include <cstdlib> #include <cstring> #include <utility> #include <iostream> #include <algorithm> #define FI first #define SE second #define LSON(x) (x<<1) #define RSON(x) ((x<<1)|1) #define Benefit(x,y) x=max(x,y) #define CS const static #define SORT_CMP(s,l,r,cmp) sort(s+(l),s+(r)+1,cmp) #define SORT(s,l,r) sort(s+(l),s+(r)+1) #define MP(x,y) make_pair(x,y) #define Randomize srand( (unsigned int) time ( NULL ) ) #define INOUT(x,y) freopen(x,"r",stdin),freopen(y,"w",stdout) using namespace std; typedef char name[20]; CS int MaxN = 100010 ; struct word { name x; int val,len; word() {x[0] = 0; val = 0;} }; struct Trie { Trie * next[26]; word * ans[10]; Trie() { for(int i=0;i<26;i++) next[i] = NULL ; for(int i=0;i<10;i++) ans[i] = NULL ; } } * Tree; word p[MaxN]; name ask; int n,m,asklen; void Insert(Trie * x,int _y,int pos) { int i; word & y = p[_y]; for(i=0;i<10;i++) if((x->ans[i]==NULL)||(x->ans[i]->val<y.val)) break; if(i<10) { for(int j=9;j>i;j--) x -> ans[j] = x->ans[j-1]; x -> ans[i] = p + _y; } if(pos!=y.len) { int u = y.x[pos] - 'a'; if(!x->next[u]) x -> next[u] = new Trie ; Insert(x->next[u],_y,pos+1); } } void Init() { scanf("%d\n",&n); Tree = new Trie ; for(int i=1;i<=n;i++) { scanf("%s %d\n",p[i].x,&p[i].val); p[i].len=strlen(p[i].x); Insert(Tree,i,0); } } void Query(Trie * x,int pos) { if(pos == asklen) { for(int i=0;i<10;i++) if(x->ans[i]) printf("%s\n",x->ans[i]->x); else break; return ; } int u = ask[pos] - 'a'; if(x->next[u]) Query(x->next[u],pos+1); } void Solve() { scanf("%d\n",&m); while(m--) { scanf("%s\n",ask); asklen = strlen(ask) ; Query(Tree,0); if(m) printf("\n"); } } int main() { Init(); Solve(); return 0; } Edited by author 31.05.2012 14:40 you are an idiot. why so many inclusions? and your code is delirium. ...wrote Nikolay, 43 solved problems and 6000+-th place, to blablabla, 280 solved problems and place within top 1000. P.S. And the code style is not great, but quite okay. Edited by author 19.11.2014 12:32 Some hint: For n = 4 1 : (1,2), (1,3), (1,4); 2 : (2,1), (2,3); 3 : (3,1), (3,2); 4 : (4,1); 1st have 3 friends, 2nd have 2 friends, 3d have 2 friends, 4fth have 1 friend, so ans is 4 1 2 1 3 1 4 2 3 FOR 5 -1000 10.09 21:00 +500 09.09 14:00 +1000 02.09 00:00 -1000 17.09 21:00 +500 18.09 13:00 ANSWER IS -1000 -500 0 -500 -500 OR -1000 -500 0 -500 0 The first one. Jenya never puts earned money into the credit account. why then the 2nd debt is -500 not -1000? date,understand Edited by author 18.11.2014 13:14 please help me !!!!!!!! I submissions 14 time this is my code #include<stdio.h> int main() { char str0[100]; int str1[100],str2[100],str3[100]; int i,len=0; gets(str0); for(i=0;str0[i]!='\0';i++,len++) str1[i]=str0[i]-'a';
str2[0]=str1[0]; for(i=1;i<len;i++) { str2[i]=str1[i]; while(str2[i]<str2[i-1]) { str2[i]+=26;
} }
str3[0]=str2[0]-5; for(i=0;i<len;i++) str3[i+1]=str2[i+1]-str2[i];
for(i=0;i<len;i++) printf("%c",(str3[i]%26)+'a');
} Edited by author 28.11.2006 22:06 Edited by author 28.11.2006 22:08 not (a[0] in ['a'..'z'])!! What I wanna tell you is that this problem is really easy to solve. You only need to have a really good thinking. Try to find the changes between each letters or numbers. Then you'll work it out! The problem is that you haven't considered the case where str[0]<'a'+5. In this case when you do str[0]-=5 at the end a value lesser than 'a' may be obtained. Hence at the end if (str[0]-=5)<0 then str[0]+=26. Try this test case once bimdhhycaoinese Answer should be whereareyoufrom you get [hereareyoufrom if you havent taken care of the condition. <<jagatsastry>> A lot of Thanks)) <jagatsastry> Thank you very much for explanation <jagatsastry> Thank you very much for explanation What is wrong with test 4? 5 6 5 4 9 4 2 6 5 1 6 1 2 3 5 3 8 3 2 5 IMPOSSIBLE 0.00 3.00 2.00 3.00 6.00 Isn't this the correct answer? :? Nevermind, it is actually undeterminable. Edited by author 16.11.2014 22:56 Edited by author 16.11.2014 23:08 /// What's wrong? var a,b,c,i,s:integer; m:array[1..1000000] of integer; begin s:=0; read(a); read(b); for i:=1 to b do begin read(m[i]); if(m[i]>a) then s:=s+m[i]-a else begin if s>m[i]+a then s:=s-m[i]-a else s:=0; end; end; if s<0 then writeln(0) else writeln(s); end. I found my error. I was searched all multiples of i<=LIMIT, whereas right i*i<=LIMIT. Now my code not run firsth test..but i am sure that result is correct. Please, give me some input data for test. Дайте тест №2, ну или все тесты на эту задачу!!! yes... i need it too +1 For example: 4 15000 14000 15000 14000 It can be test if you have TLE, try this 15000 15000 15000 ... 15000 (15001 lines) or 15000 1 2 ... 14999 15000 Hint for check: 15000th prime number is 163841 you sure that 15000th prime number is 163841? i think that it 163847 Please don't make so stupid mistakes that I did. Lost about 3 hours on the contest, gratz to me. Anti-WA #51: 4 0 0 2 0 1 1 1 2 Answer: oo Anti-WA #52: 4 0 0 1 2 2 2 3 0 Answer: oo it's very simple,especially on java. The order of 1's within the number is 1 2 4 7 11 16 ...You can find the n'th number in sequence is equal to 1+n*(n-1)/2. So for any given input a, it is sufficient to test whether or not (a-1)*2 is equal to multiplication of two consequence number. I hope it helps What is test case 4? please help yes, give 4 test Edited by author 16.11.2014 02:42 var n,i: integer; x1,x2,y2,y1,xx,yy,e,r: real; begin readln(n,r); readln(x1,y1); yy:=y1; xx:=x1; for i:=2 to n do begin readln(x2,y2); e:=e+sqrt(sqr(x2-x1)+sqr(y2-y1)); x1:=x2; y1:=y2; end; writeln((round((e+2*3.14159*r+sqrt(sqr(xx-x1)+sqr(yy-y1)))*100))/100); end. I'm using Heavy light Decomposition an I'm getting ML in test 9 WHY ???? could you give me test #7? I can not understand what is wrong! |
|