Common BoardNeed more tests to pass 14th test. Can anybody give me it? #include <iostream> using namespace std; int i,n,a[25],b=0,g,c[25]={0}; void p(int s) { int j; g=min(g,abs(b-s*2)); for (j=0;j<n;j++) { if (c[j]==0) { s+=a[j];c[j]=1; p(s); s-=a[j];c[j]=0; } } } int main() { cin>>n; for (i=0;i<n;i++) { cin>>a[i]; b+=a[i]; } g=b; p(0); cout<<g; return 0; } Edited by author 17.06.2009 18:55 19 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 70 Could anyone help me? This code get CRASH... #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { // Input Database int num_elem_db; cin >> num_elem_db; vector<int> data_vector (num_elem_db, 0); // Vector for data for (int i = 0; i < num_elem_db; ++i) { int aux_elem; cin >> aux_elem; data_vector[i] = aux_elem; } cout << "###" << endl; // SORTING VECTOR OF DATA sort( data_vector.begin( ), data_vector.end( ) ); // Input queries int num_queries; cin >> num_queries; vector<int> query_vector (num_queries, 0); // Vector for queries for (int j = 0; j < num_queries; ++j) { int aux_query; cin >> aux_query; query_vector[j] = aux_query; } for (int k = 0; k < num_queries; ++k) { cout << data_vector[query_vector[k]-1] << endl; } return 0; } Please HELP!!! give me tests or say what is wrong: #include <iostream> using namespace std; int is[128000]; int main() { int n, n1, a, c=10000; cin >> n; for(int i=0; i<n; i++) { cin >> a; if(a>=0) is[a]=1; else is[a-2*a+32767]=1; } cin >> n1; bool kl=false; for(int i=0; i<n1; i++) { cin >> a; if(a<c && c-a<=32767) if(is[c-a]) { cout << "YES" << endl; return 0;} if(a>c) if(is[a-c+36767]) { cout << "YES" << endl; return 0;} } cout << "NO" << endl; return 0; } What is this test. What is my mistake #include <cstdio> #include <iostream> #include <cmath> using namespace std; int main() { int n; double r, a[128], b[128], P=0; scanf("%d%lf", &n, &r); for(int i=0; i<n; i++) { scanf("%lf%lf", &a[i], &b[i]); if(i>0) { P+=sqrt((a[i]-a[i-1])*(a[i]-a[i-1])+(b[i]-b[i-1])*(b[i]-b[i-1])); if(n==2) P+=sqrt((a[i]-a[i-1])*(a[i]-a[i-1])+(b[i]-b[i-1])*(b[i]-b[i-1])); } if(i==n-1) P+=sqrt((a[i]-a[0])*(a[i]-a[0])+(b[i]-b[0])*(b[i]-b[0])); } P+=2*r*acos(-1.0); printf("%4.2lf\n", P); }
how to do it for 0,001 seconds???? I have find my bug,and AC now! Just try to find a start point,and then bfs,find the minimum depth. Edited by author 15.06.2009 19:18 Hi! Here is my source - I compiled it on Visual C++ and it is OK - but here got "compilation Error". Could anyone explain me why??? #include <stdio.h> long x1,x2,y1,y2,ymin,ymax,n,i,posy,disttt; void main() { bool boo; boo=false; scanf("%ld",&n); scanf("%ld%ld%ld%ld",&x1,&y1,&x2,&y2); disttt=0; posy=1; ymin=y1; ymax=y2; for(i=1;i<n;i++) { scanf("%ld%ld%ld%ld",&x1,&y1,&x2,&y2); if(y1>=ymax-1||y2<=ymin+1) { printf("-1\n"); boo=true;; } if (posy<=y1) { disttt+=(y1+1-posy); posy=y1+1; } else if (posy>=y2) { disttt+=posy-y2+1; posy=y2-1; } ymin=y1; ymax=y2; } disttt+=x2-2; if (posy>y2-1) disttt+=posy+1-y2; else if(posy<y2-1) disttt+=y2-1-posy; if (boo==false) printf("%ld\n",disttt); } Thanks! Try replacing y1 with y1_ and y2 with y2_. You will get accepted. The same thing happened to me. Do not use bool,the compiler may not support this I think my code is right,but it was getting wa wa all the time. So I started to change it. I saw the code above,so I changed mine more and more like that. But a surprising thing ,my code is even equal to the code above, but it got accepted,but my still wa. I wonder.............. my code #include<iostream> #include<string> #include<memory> using namespace std; int main(void) { long n; cin>>n; long nowy=1,i,maxy,miny,x1,y1,x2,y2; long dist=0; cin>>x1>>miny>>x2>>maxy; bool ok=true; for(i=1;i<n;++i){ cin>>x1>>y1>>x2>>y2; if(y1>=maxy-1||y2<=miny+1){ ok=false; break; } if(y1>=nowy){ dist+=y1+1-nowy; nowy=y1+1; } else if(y2<=nowy){ dist+=nowy-y2+1; nowy=y2-1; } miny=y1; maxy=y2; } if(ok){ dist+=x2-2; //dist+=abs(y2-1-nowy); if(nowy>y2-1)dist+=nowy+1-y2; else if(nowy<y2-1)dist+=y2-1-nowy; cout<<dist<<endl; } else cout<<"-1"<<endl; return 0; } I pass all tests, that I think up. Can anybody give me more tests??? I've been solving the problem number 1331 for a week. I've checked everything! It has to be right. It works with the data which is given as an example, but the Judge gives my "Wrong answer" How can i know why my problem isn't working? I submitted this problem in C++ and got WA #2. It used getline and C++ strings. Then I rewrote it in Pascal and got AC. I really don't understand why. Explain it to me, please. Does anyone know, what can be in it? My program passes all the tests from the forum on other cases. WA #7 also is very rarely WA. I read char by char using while(c!=EOF) and getchar(). The trouble was printing redundant "Enter" when the 40th symbol is not the symbol of word. A limitation of 10000 is weak. My "stupid" O(n^2) PASCAL solution gets AC in 0.078 sec. It works very fast even on its worth test: aaaa....aaaab (9999 letters 'a') where it makes 9999 iterations with = and Delete() with strings of length 10000. But actually I don't know how to change this. If just increase limitation, even correct solutions gets WA... Maybe it is actual to make version 2 of problem, with limitation in 100000 or 250000. for example test : 2 2 1 2 2 1 1 2 the answer is NO, not YES I need that anyone explain me me how to resolve this problem: Can yo help with the resolution of the fallowing problem: A triangle made of coins of height h is as follows: It has h coins at the base and h-1 coins one level above base and so on.(Coins are placed as shown in the figure below)
And at the top most level there will be only one coin Now given h the task is to invert this triangle by moving minimum number of coins. For example when h=4 triangle is For h=4 atleast 3 coins must be moved to invert it I appreciate any help or suggestione Maybe, someone knows, what is it? I don't understand why WA#4 here is my code(maybe I use uncorrect algo?): #include<iostream> #include<cmath> #include<stdio.h> using namespace std; int main() { unsigned __int64 k=0; long r; cin>>r; if(r==1) { cout<<4<<endl; return 0; } if(r==2) { cout<<16<<endl; return 0; } k=(r-1)*8; k=k+(r-1+r-1)*(r-1+r-1); printf("%I64u\n",k); return 0; } Wrong algo :] For example: r = 5 correct_answer = 88 Your formula: a = 8*(5-1) = 8*4 = 32 b = (r-1+r-1)*(r-1+r-1) = (2r-2)^2 = 8^2 = 64 res = a+b = 32 + 64 = 96 correct_answer != res -> Wrong algo :] Edited by author 12.06.2009 01:14 Thanks. I find my mistake. Edited by author 10.06.2005 01:33 Could anybody give my some difficult sample? I wanna check not trevial source data #include <iostream> #include <stdlib.h> using namespace std; int main() { int m, n, f; double out; div_t o; double way[32005] = {0}; long long int oil[32005] = {0}; cin >> n >> m; way[1] = m; oil[1] = m;
for(f = 1; way[f - 1] + m / (2 * f - 1) < n; f++) { way[f] = way[f - 1] + m / (2 * f - 1); oil[f] = f * m; } out = (n - way[f - 1]) * (2 * f - 1) + oil[f - 1]; o = div(out, 1); if(abs(out - o.quot) < 1e-8) cout << o.quot; else cout << o.quot + 1;
} |
|