Common BoardWho knows how to solve it? :?) by hands!!! at first read kormen book, knuth "the art of programming" and after that try to solve it again. #include<stdio.h> void main(){ int n,k=0,j; int result=1; char test[20]; scanf("%d %s",&n,test); for (j=0;j<20;j++) if (test[j]=='!') k++; if(n%k==0){ for(j=0;n-j*k!=k;j++){ result*=(n-j*k); }; result*=k; }else{ for(j=0;n-j*k!=n%k;j++){ result*=(n-j*k); }; result*=n%k; }; printf("%d",result); } this is my source code please tell me why my program is time limited exceeded #include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <utility> using namespace std; const int maxN = 304; int x[maxN], y[maxN]; int n; vector< pair<int, int> > p; bool mark[maxN][maxN]; int dist(const int& i, const int& j) { return (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]); } bool compairation(const pair<int, int>& p1, const pair<int, int>& p2) { return (dist(p1.first, p1.second) > dist(p2.first, p2.second)); } int ccw(const int& i, const int& j, const int& k) { int dx1 = x[j] - x[i], dy1 = y[j] - y[i]; int dx2 = x[k] - x[j], dy2 = y[k] - y[j]; return (dx1 * dy2 - dx2 * dy1); } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];
for (int i = 1; i < n; i++) for (int j = i + 1; j <= n; j++) p.push_back(pair<int, int>(i, j)); sort(p.begin(), p.end(), compairation);
memset(mark, true, sizeof(mark));
double total = 0.0; for (int i = 0; i < p.size(); i++) if (mark[p[i].first][p[i].second]) { int d = p[i].first, c = p[i].second; vector<int> point; point.clear(); for (int j = 1; j <= n; j++) if (ccw(d, j, c) == 0) point.push_back(j); for (int u = 0; u < point.size(); u++) for (int v = u + 1; v < point.size(); v++) { mark[point[u]][point[v]] = false; mark[point[v]][point[u]] = false; //cout << point[u] << " " << point[v] << endl; } total += sqrt(double(dist(d, c))); }
cout << round(total) << endl;
return 0; } cout << round(total) << endl;//<Mistake here There is no function round() in C++. Edited by author 01.02.2008 02:11 Or try follow: Set #include<stdio.h> and write printf("%0.lf",total); I think it will be more helpful. Edited by author 01.02.2008 01:42 Edited by author 01.02.2008 02:11 Thank you very much! I've got AC. But i compiled it sucessfully by DevC++ and Eclipse IDE. (It also uses g++ compiler). Please tell me why ????? Edited by author 01.02.2008 19:05 As far as I know there is no standart function round() in C++.For more information read FAQ.Good luck! <code deleted> Edited by author 19.02.2008 00:29 Please consider the Sample input and output : The 1st flight ( connects 1 and 2 ) and the 2-nd flight ( 2-3) are flights that depart from one airport ( airport 2 ) ( The flight are 2 directions flight ) . But the sample output indicates that their numbers are 4 and 2 , so their greatest common divisor can't be 1 as the problem description ! I don't know if I wrong . I got WA too . Please explain for me Thanks a lot ! . You must calculate greatest common divisor of all flights, that departs from one airport. For airport 2 this numbers are 2,3,4 and there greatest common divisor is 1. this is my program : #include<iostream> using namespace std; int main() { int n; cin>>n; int i; for(i=0;i<n/2;i++) cout<<i+1<<" "<<n-i<<" "; if(n%2!=0) cout<<((int)n/2)+1<<" "; cout<<endl; cout<<"1 "; for(i=3;i<n;i+=2) cout<<i<<" "; int p=n; if(p%2!=0) { p-=1; cout<<n<<" "; } for(p=p;p>1;p-=2) cout<<p<<" "; return 0; } I think its right but I get WA on test 4 anybody knows whats wrong ? I have wr . Please give me some test help help!!!!! Oh, i got ac without any help. You can try this test : 20 8 1 9 odd 10 17 odd 18 26 odd 4 5 odd 27 40 even 21 40 odd 1 20 odd 10 20 odd -1 the ans is : 6 ^_^ Edited by author 13.12.2006 15:28 Edited by author 13.12.2006 15:28 My answer is 6 too but i still get wr1 why??? I have also 6, but stupid wa 1! Please admins, correct this test! Statistic of this problem is 9%. That's not normal! Please give much more tests!! Edited by author 17.03.2007 21:35 The answer is 2, because the third one“18 26 odd”is obviously a lie,since 26>20. Edited by author 03.06.2007 10:01 Thanks for your help!i didn't pay any attention to that! Don't brute force thats the trick ! :D can you please help me about what is wrong about this? You tried to solve problem 1161 Stripies. Your solution was compiled with the following errors: 93e006e3-949c-4a74-a88f-eb4b2c6dc082 93e006e3-949c-4a74-a88f-eb4b2c6dc082(19): error: expression must have a constant value int set[N]; ^ /* why can't I declare a new array like this? (N is integer) */ 93e006e3-949c-4a74-a88f-eb4b2c6dc082(61): error: expression must have a constant value int aux[max-min+1], i=min, k=0; ^ /* The same */ 93e006e3-949c-4a74-a88f-eb4b2c6dc082(61): error: expression must have a constant value int aux[max-min+1], i=min, k=0; ^ /* Two errors on the same line!!! */ compilation aborted for 93e006e3-949c-4a74-a88f-eb4b2c6dc082 (code 2) You couldn't declare array with nonconstant value! In this case try to use dynamic array, or vector. int aux = new int[N]; or vector<int> aux(N); Thaks for helping (I didn´t tried yet) But... does C (ANSI C, not C++) accept the "vector" type or "int a = new int[10]"??? I have solved dozens of problems using "int a[x];" at UVa online judge, I think there could be more reasonable to forbid the "vector" type using (not elemental) than "int a[x];" (ANSI C elemental array using) Thanks I hope your reply Sergio Ligregni, MEX Sorry I've made a mistake... Not int aux = new int[N]; should be : int * aux = new int[N]; P.S. I don't know how to be with ANSI C, because I've never use it... P.P.S. I always use vector(or other STL containers). Here are some tests: 10 1 10 + 0 = 10 21 0 43 0 100 3 91 + 9 = 100 95 + 5 = 100 100 + 00 = 100 4444 6 3722 + 722 = 4444 4022 + 422 = 4444 4037 + 407 = 4444 4040 + 404 = 4444 4042 + 402 = 4444 4222 + 222 = 4444 6667 1 6061 + 606 = 6667 6668 6 5834 + 834 = 6668 6034 + 634 = 6668 6059 + 609 = 6668 6062 + 606 = 6668 6064 + 604 = 6668 6334 + 334 = 6668 66667 1 60607 + 6060 = 66667 66668 7 58334 + 8334 = 66668 60334 + 6334 = 66668 60584 + 6084 = 66668 60604 + 6064 = 66668 60608 + 6060 = 66668 60634 + 6034 = 66668 63334 + 3334 = 66668 52525252 11 46262626 + 6262626 = 52525252 47747626 + 4777626 = 52525252 47750126 + 4775126 = 52525252 47750176 + 4775076 = 52525252 47750226 + 4775026 = 52525252 47750231 + 4775021 = 52525252 47752626 + 4772626 = 52525252 47762626 + 4762626 = 52525252 47812626 + 4712626 = 52525252 48262626 + 4262626 = 52525252 51262626 + 1262626 = 52525252 456000 10 378000 + 78000 = 456000 408000 + 48000 = 456000 413000 + 43000 = 456000 414500 + 41500 = 456000 414545 + 41455 = 456000 414546 + 41454 = 456000 414550 + 41450 = 456000 414600 + 41400 = 456000 415000 + 41000 = 456000 428000 + 28000 = 456000 123000321 1 111818474 + 11181847 = 123000321 200020002 16 150010001 + 50010001 = 200020002 181510001 + 18510001 = 200020002 181835001 + 18185001 = 200020002 181836351 + 18183651 = 200020002 181836366 + 18183636 = 200020002 181836371 + 18183631 = 200020002 181836401 + 18183601 = 200020002 181836501 + 18183501 = 200020002 181837001 + 18183001 = 200020002 181840001 + 18180001 = 200020002 181860001 + 18160001 = 200020002 181910001 + 18110001 = 200020002 182010001 + 18010001 = 200020002 185010001 + 15010001 = 200020002 190010001 + 10010001 = 200020002 200010001 + 00010001 = 200020002 1000000000 13 905000000 + 95000000 = 1000000000 909050000 + 90950000 = 1000000000 909090500 + 90909500 = 1000000000 909090905 + 90909095 = 1000000000 909090910 + 90909090 = 1000000000 909090950 + 90909050 = 1000000000 909091000 + 90909000 = 1000000000 909095000 + 90905000 = 1000000000 909100000 + 90900000 = 1000000000 909500000 + 90500000 = 1000000000 910000000 + 90000000 = 1000000000 950000000 + 50000000 = 1000000000 1000000000 + 000000000 = 1000000000 Should i use long ariphmetics??? How should i correctly calculate the value of polynom for given variable? Interesting question. I think that is important to understand distinction between root and point of small value. Now i am solving 1503 but have wa9. I have program for finding all roots in complex plane but can't improve precision from 0.0001 to 0.000001. For it would enough to have float with 30 right digits. Question depend also on position of testmakers. I think that if we have a +0.000001*i complex root then answer a+-0.000001 must be right. To approach root near 0.000001 we must have 30 digits int results. I've calculated precision up to last digit of standard pascal's type Extended, so, my precision should be up to 1e-16. But still WA #9... Edited by author 03.11.2006 14:45 example: x^5==0 x0=0-root; x1=0.00001- bad value but x1^5=1.0*E-25- very small My reqursive approach of solving equation P(x)=0 is: to solve equation P'(x)=0, and then binary search on all the intervals, whose ends are roots of equation P'(x)=0. So, I haven't problems with "excess psevdoroots", but still WA #9... Eqution P'(x)=0 is also bad because P'(x) may has multiple roots. It should start from d(N-1)P/dx=0 which is linear and go up applying binary search on each stage. If root multiple then on previous stage it was simple and is founded. As result all candidates for roots will be found with hight precision. The problem is to make choice which of them are roots of P(x)=0. Here we must use existence theoren of Sturm . Simplest variant is P(a)*P(b)<0=> x in [a,b]. I used with success long aritmetic and now on WA16. AC finally. In Java only using my BigFraction baseg on BigInt I implemented famous Stourm's theorem which garantees absolutely correct considering multiple roots without any eps and so on. But in question what degree of found multiple root I needed in unknown constant h which garantes that if d/dtP(t)!=0 and P(t)==0 than in (t-h,t+h) d/dtP(t)!=0. I taken h=1e-12. In other words I think that if P(t)==0 and in (t-h,t+h) exists t1 such that d/dtP(t1)==0 then t==t1. h=1e-6 works also. Edited by author 08.12.2007 19:43 Eqution P'(x)=0 is also bad because P'(x) may has multiple roots. It should start from d(N-1)P/dx=0 which is linear and go up applying binary search on each stage. If root multiple then on previous stage it was simple and is founded. As result all candidates for roots will be found with hight precision. The problem is to make choice which of them are roots of P(x)=0. Here we must use existence theoren of Sturm . Simplest variant is P(a)*P(b)<0=> x in [a,b]. I used with success long aritmetic and now on WA16. i do it more simply. int r[n] - array of int which represent roots P'(x) int i,j; for (i=0;i<n;i++) for (j=0;j<n;j++) if (i!=j) trytofindroot(P,r[i],r[j]); Edited by author 04.11.2006 15:41Should i use long ariphmetics??? How should i correctly calculate the value of polynom for given variable? I think it's impossible to calculate P(x) with given accuracy (10^-6), without long arrithmetics Fortunatelly, it is possible... :) I don't know what in fact is the problem with test #9 but I had WA10 and the problem with is was the equal roots. If you concern about these particular cases, you won't have the need of long arrithmetics (I don't wish long float arithmetics to anyone!!!) And what problem with my approach, when P'(x) has multiple roots? At some stage we make binsearch from x to x, where x - multiple root, and, as a result, we'll get still 3 new roots of P(x). For input 5 1 0 0 0 0 0 my program outputs 0 0 0 0 0 I think, it is right answer. Isn't it? Edited by author 06.11.2006 00:54 Fortunatelly, it is possible... :)quote> and how I can do it? Vedernikoff Sergey: yes, this output is correct. Alexander Prudaev: I had a precision error but eliminated it by checking whether the given function has zero value for the borders of the searching interval. p.s. I am sorry for the late post. I haven't seen your posts (it might be usefull the admins to create an informational/notificational system) Edited by author 17.01.2007 06:59 Edited by author 24.01.2007 02:22 Edited by author 24.01.2007 02:23 I solve it problem with long double!! Did you use Ferrary method or Euler solution for polynomial of fourth degree? I understood that you don't find root using general methods because of your time. I solved this problem, but my program is wrong at 4 test. Where is mistake? var l,k,j,m,n,mistake,o,sum,p,w:integer; text1:string; z,text:array[1..100]of string; begin o:=1; repeat inc(l); readln(z[l]); until z[l]='#'; dec(l); repeat inc(j); readln(text[j]); until text[j]=''; dec(j); for k:=1 to l do for m:=1 to j do begin for n:=1 to length(text[m]) do begin text1:=''; while text[m][o] in ['a'..'z'] do begin text1:=text1+text[m][o]; inc(o); end; if length(text1)=length(z[k]) then begin for w:=1 to length(z[k]) do if text1[w]<>z[k][w] then inc(mistake); if mistake=1 then begin inc(sum); for p:=1 to length(z[k]) do begin text[m][o-length(text1)+p-1]:=z[k][p]; end; end; mistake:=0; end; inc(o); end; o:=1; (*----------------------*) end; for k:=1 to j do writeln(text[k]); writeln(sum); end. I also have WA 4. Does anybody know what is wrong with it? My program doesn't work on this test. Please, tell me what's wrong with it: #include <stdio.h> int C[500][500],R[500][500],U[500],T[500]; int main(int argc, char* argv[]) { int N,M,start,finish,s,a,b,c,S,F,i,j,u; scanf("%d%d",&N,&M); start=N; s=N-1; for (i=0;i<M;i++) { scanf("%d%d%d",&a,&b,&c); C[a-1][b-1]=c; T[a-1]++; } scanf("%d%d",&S,&F); S--; F--; U[s]=F; for (i=0;i<N;i++) if (i!=S&&i!=F&&T[i]==0) { s--; U[s]=i; } do { finish=start-1; start=s; for (i=finish;i>=start;i--) { b=U[i]; for (j=0;j<N;j++) if (C[j][b]!=0&&j!=S) { T[j]--; if (T[j]==0) { s--; U[s]=j; } } } } while (s<start); U[0]=S; for (i=0;i<N;i++) { a=U[i]; for (j=0;j<N;j++) R[i][j]=C[a][j]; } for (i=0;i<N;i++) { b=U[i]; U[i]=-1; for (j=0;j<N;j++) C[j][i]=R[j][b]; } U[N-1]=0; for (i=N-2;i>=0;i--) { for (j=i+1;j<N;j++) if (C[i][j]!=0&&U[j]!=-1) { u=C[i][j]+U[j]; if (u>U[i]) U[i]=u; } } if (U[0]==-1) printf("No solution"); else printf("%d",U[0]); return 0; } please give me some tests! I've got WA on #3, too. But, why? Now I have AC. But I don't remember my bugs. #input 0.0 0.0 2.0 0.0 0 #output 3 0.0 0.0 1.0 0.0 2.0 0.0 This output is correct, isn't it? Corrected. Should be %I64d for long long variables, not %lld. Now I have AC. ----------------------------------------------------------- printf("%lld %lld",max_wynik,min_wynik); <---- BAD printf("%I64d %I64d,max_wynik,min_wynik); <---- GOOD Edited by author 15.02.2008 02:51 What's wrong? #include <stdio.h> #include <stdlib.h> int n,x,s; typedef struct{ int t1,t2,t3; }st; st t[110]; int max(int a,int b){ if(a>b)return a; else return b; } int cmp(const void *a,const void *b){ const st *c=(st *)a, *d=(st *)b; return c->t1 - d->t1; } int main(){ scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d %d %d",&t[i].t1,&t[i].t2,&t[i].t3); } qsort(t,n,sizeof(st),cmp); for(int i=0;i<n;i++){ t[i].t1=max(t[i].t1,x); x=t[i].t1 + t[i].t2; s+=max(0,x-t[i].t3); } printf("%d\n",s); return 0; } Some limitations are identical, and when I used counter for entering edges to each vertex, I get WA15). Edited by author 28.01.2008 12:26 what's the answer of 5 = =" Can u tell me..? I have no hint.. T_T Can i accept by use relation of sequence? I tested my program several times but I can't find what's wrong with it please help ! my program : #include<iostream> #include<stdio.h> using namespace std; int main() { char a[1000000]; cin>>a; int i; int counter=0; int maxint=0; for(i=0;i<strlen(a);i++) { if(a[i]>64){ if(maxint<a[i]-55) maxint=a[i]-55; counter+=a[i]-55; } else { if(maxint<a[i]-48) maxint=a[i]-48; counter+=a[i]-48; } } for(i=1;i<36;i++) { if((counter%i==0)&&(maxint<i)) { cout<<i+1; return 0; } } cout<<"No solution."; return 0; } |
|