Common BoardPlease help me, look over my code, I'll be thankfull to anyone who will find mistake in my code, or give me some tests. var h,s,aa,bb:real; a:array[1..3,1..2] of integer; i,l:integer; procedure readdata; begin readln(a[1,1],a[1,2],a[2,1],a[2,2]); readln(a[3,1],a[3,2],l); end; procedure writedata; begin writeln(aa:0:2); writeln(bb:0:2); end; function d(x1,y1,x2,y2:integer):real; begin d:=sqrt(sqr(x1-x2)+sqr(y1-y2)); end; procedure square; var p,a1,a2,a3:real; begin a1:=d(a[1,1],a[1,2],a[2,1],a[2,2]); a2:=d(a[3,1],a[3,2],a[2,1],a[2,2]); a3:=d(a[1,1],a[1,2],a[3,1],a[3,2]); p:=(a1+a2+a3)/2; s:=sqrt(p*(p-a1)*(p-a2)*(p-a2)); end; begin readdata; square; h:=d(a[1,1],a[1,2],a[2,1],a[2,2]); aa:=s/(0.5*h); if d(a[1,1],a[1,2],a[3,1],a[3,2])<aa then aa:=d(a[1,1],a[1,2],a[3,1],a[3,2]); if d(a[2,1],a[2,2],a[3,1],a[3,2])<aa then aa:=d(a[2,1],a[2,2],a[3,1],a[3,2]); bb:=d(a[3,1],a[3,2],a[2,1],a[2,2]); if d(a[3,1],a[3,2],a[1,1],a[1,2])>bb then bb:=d(a[3,1],a[3,2],a[1,1],a[1,2]); if (s/(0.5*h))>bb then bb:=(s/(0.5*h)); aa:=aa-l; bb:=bb-l; writedata; end. 2 1 4 2 0 0 1 YOUR: -1.00???? 3.47 AC: 1.24 3.47 What do you think how it can be changed? :):):):):):):):):):):):):):):)+++++++++++++++++++++ I'm not talking about decision, decision is right. I said that how code can be changed to get AC? I modified my code, it gives correct answer for your test but i still get this ****** WA#4 !!! Here is code var a1,a2,a3,h,s,aa,bb:real; a:array[1..3,1..2] of integer; i,l:integer; procedure readdata; begin reset(input);} readln(a[1,1],a[1,2],a[2,1],a[2,2]); readln(a[3,1],a[3,2],l); end; procedure writedata; begin writeln(aa:0:2); writeln(bb:0:2); end; function d(x1,y1,x2,y2:integer):real; begin d:=sqrt(sqr(x1-x2)+sqr(y1-y2)); end; procedure square; var p:real; begin a1:=d(a[1,1],a[1,2],a[2,1],a[2,2]); a2:=d(a[3,1],a[3,2],a[2,1],a[2,2]); a3:=d(a[1,1],a[1,2],a[3,1],a[3,2]); p:=(a1+a2+a3)/2; s:=sqrt(p*(p-a1)*(p-a2)*(p-a2)); end; begin readdata; square; if (a1*a1+a2*a2<a3*a3) or (a2*a2+a3*a3<a1*a1) or (a1*a1+a3*a3<a2*a2) then begin aa:=d(a[1,1],a[1,2],a[3,1],a[3,2]); if d(a[2,1],a[2,2],a[3,1],a[3,2])<aa then aa:=d(a[2,1],a[2,2],a[3,1],a[3,2]); end else begin h:=d(a[1,1],a[1,2],a[2,1],a[2,2]); aa:=s/(0.5*h); end; bb:=d(a[3,1],a[3,2],a[2,1],a[2,2]); if d(a[3,1],a[3,2],a[1,1],a[1,2])>bb then bb:=d(a[3,1],a[3,2],a[1,1],a[1,2]); aa:=aa-l; bb:=bb-l; writedata; end. Seems correct but gets WA#4 aa always >=0 bb always >=0 Before an input in procedure write make terms that was not aa <0 and bb <0 Maybe I'm Error,But,What mistake you think?I can not to found any mistake At a conclusion check up that aa and bb were not negative, If they will be negative appropriate him 0. Spaces and line feeds can follow each other in any order, so you need only to Read([1,1],a[1,2],a[2,1],a[2,2],a[3,1],a[3,2],l); -5 0 5 0 0 5 100 Correct answer is 0.00 0.00 Is example in problem right? I think it is not!!! if there is a route like below: 3 1 2 3 Can I go from station 3 to station 1 directly? I mean, is the route a circle? Bellman-Ford I used two SSSP algo (BFS + DFS) to solve the problem. Can it be done with only one ? how to determinate the shortest route??? Why in the test input the criminal goes to 85 and not to 10 or 75???? I too Edited by author 21.04.2004 00:39 First do BFS with the first node in the criminal's route. Save the result in the array d1. Do another BFS with the last node in the criminal's route, and save the result in the array d2. For any node i, if d1[i]-d2[i]=m-1, then i is an answer. The graph is always connected. I build BFS traversal tree by giving priorities to points on the route (i.e. advance them first). Children of the last route node gain privelege for the rest of traversal (if you process nodes in the order they were first visited, this condition is automatic because they will be added prior to any other nodes during last privileged propagation). After BFS tree is ready, nodes reachable from last node on the route inside that tree form the answer. Edited by author 01.08.2008 05:09 What is the minimal value for Ai? "Let a commander and his subordinate have computers with numbers i and k respectively. According to the contract with the provider, the traffic between the computers i and k must be not less than Ai–Ak." Can Ai-Ak<0 ? You should consider both (Ai-Ak) and (Ak-Ai). Thus traffic >= max(Ai-Ak , Ak-Ai). My AC solution assumes Traffic = max(Ai-Ak, 0) what is the solution for this problem? A formula. I understood that after seeing that AC solutions used 100Kb memory and about 0.001-0.015 sec. Give me some hints Ostap. :) I've spent many hours on it but still no luck :) My solution was "half guessing / half interpolation" :) I just bruteforced few answers. Guessed the denominator of the formula and then counted it's numerator assuming that it is a polynomial of degree 2. Later after the contest Vasya told me, that he produced that formula on paper theoretically. So, the strict theoretical approach is also possible. But guessing is much faster :) It's amaizing!!! Yours solution is just great (much better than Vasya's math solution), it took about 5-10mins to get AC! Thanks Ostap! Edited by author 31.03.2008 14:16 Do you need to find GCD in your solution ? Or GCD(denom, num) = 1 in your formula ? Is it so important? But - yes, i used GCD in my solution. Well, formula is simpler than expected. No factorials and big numbers. Probably I incorrectly computed answers for small n-s during contest :( Cool problem! But does anybody know the mathematical proof? I think it can be proven by induction. Though, it most probably won't give you "sense of the things", you'll have that proof :) So far my thoughts are the following: 1. Since we remove the leftmost pair, we can lay down the whole deck at once and then perform sifting. This simplifies further thoughts a bit. 2. It might be more convenient to count amount of unsiftable final positions multiplied by number of original permutations converging to them. Unsiftable positions will be of the form ABBAABBAABB.. or AABBAABBAABB.. due to suits restriction. I think that multiplier erradicates most of (2n)! in denominator, and since history effect is 2-cards wide, the answer will be 2-polynomial. #include<stdio.h> #include<stdlib.h> #define MAX 1002 int join[MAX][MAX],cont[MAX],used[MAX],win[MAX]; int np,mark,fri; int tree(int aa) { int i,j,k,mar=0,min1=MAX,min2=MAX; used[aa]=1; if(cont[aa]==1&&aa!=fri)//!!cout为1可为终点,亦可为起点~!! { win[aa]=aa; return 0; } for(i=1;i<=np;i++) { if(join[aa][i]&&!used[i]) {
k=tree(i); if(!k&&min1>win[i]) { mar=1; min1=win[i]; } if(k&&min2>win[i]) min2=win[i]; } } if(mar) { win[aa]=min1; return 1; } else { win[aa]=min2; return 0; } } int main() { int i,j,k,mar=0; scanf("%d%d",&np,&fri); for(i=1;i<np;i++) { scanf("%d%d",&j,&k); join[j][k]=1; join[k][j]=1; cont[j]++; cont[k]++; } k=tree(fri); if(k)printf("First player wins flying to airport %d\n",win[fri]); else printf("First player loses\n"); // system("pause"); return 0; } I find where I made the mistake, I just misunderstand the porblem... This is my prog #include<iostream> using namespace std; int a[102][502]={{0}},path[102][502]={{0}}; int n,m; void matr(int i) { int j; int p1[500]={0},p2[500]={0}; int pre1[500],pre2[500]; p1[0]=p2[n+1]=10000; // left to right for(j=1;j<=n;j++) if(p1[j-1]+a[i][j]>a[i][j]+a[i-1][j]){p1[j]=a[i][j]+a[i-1][j];pre1[j]=j;} else{p1[j]=p1[j-1]+a[i][j];pre1[j]=j-1;} //right to left for(j=n;j>=1;j--) if(p2[j+1]+a[i][j]>a[i][j]+a[i-1][j]){p2[j]=a[i][j]+a[i-1][j];pre2[j]=j;} else {p2[j]=p2[j+1]+a[i][j];pre2[j]=j+1;} //sravnenie for(j=1;j<=n;j++) { if(p1[j]>p2[j]){a[i][j]=p2[j];path[i][j]=pre2[j];}else{a[i][j]=p1[j];path[i][j]=pre1[j];} p1[j]=p2[j]=0; } } int main() { int i,j,min=10000,mini;
cin>>m>>n; for(i=1;i<=m;i++) { a[i][0]=a[i][n+1]=10000; for(j=1;j<=n;j++)cin>>a[i][j]; } for(i=2;i<=m;i++)matr(i); for(i=1;i<=n;i++) if(min>a[m][i]){min=a[m][i];mini=i;}; int k1=m,k2=mini,kol=1,ans[500]; if(m==1)cout<<mini;else{ ans[kol]=k2; do { kol++; ans[kol]=path[k1][k2]; if(path[k1][k2]==k2)k1--;else k2=path[k1][k2]; }while(path[k1][k2]!=0);
for(i=kol;i>=1;i--)cout<<ans[i]<<" ";} return 0; } Some people might not know English. Anyway, it is a Russian website, it has to have a Russian version of anything. But so far almost one fourth of the tasks or more does not have a Russian version. All of the tasks that did not have a Russian version two years ago still do not have one. Is it really so hard for the admins to spend one day translating the tasks into Russian? Edited by author 31.07.2008 06:35 #include <iostream> #include <stdlib.h> long long x[150001],y[150001]; using namespace std; int main(int argc, char *argv[]) { long n,f[101],i,j; for(i=0;i<=100;i++) f[i]=0; cin>>n; for(i=0;i<n;i++) {cin>>x[i]>>y[i]; f[y[i]]=1;} for(i=100;i>=0;i--) if(f[i]==1) for(j=0;j<n;j++) if(y[j]==i) cout<<x[j]<<" "<<y[j]<<endl; system("PAUSE"); return 0; } put // before system("PAUSE"); Funny to say, but once I've read this problem, I remembered the simplex method we were taught last year. The classic problem of simplex method is like this: find min(max)f(X)=C1*X1+C2*x2+c3*x3.. where ci - constants Also where is a system of conditions: a11*x1+..<=(>=)b1 a21*x1+..<=(>=)b2 and so on. The simplex method finds the solution very fast, but it can be a real value, not an integer. There is also a modification of SM called integer SM - it will find an integer solution. Is the problem based on this algo or not? Thanks for allowing. I think I've seen in Kormen a chapter how to model linear programming with graphs (unbelievable, isn't it?). I'll see what will happen I think you may round all BR down and all BC up to get integer solution. Hungarian method of weighted matching! It's interesting that I solved 1449 by first version of program without any optimization. It,s rather strange because commonly challange team prepear most difficult tests with respect to time and memory. Now the problem has junior level. This is a pity, because matching frequently using on various contests. For information: Let W- weight of maximal matching in A[][] Graph. Then W- our answer. I don't consider myself a weak problem solver (even been to ACM WF twice), but it's still not obvious for me how does this problem resolve to maximal matching, and how should I convert that matching into result :) So, the problem is worth it. subj W....... .W...... .....W.. ..B.B... ...B.... ........ ........ ........ answer: 1 0 also answer??? Edited by author 25.02.2006 14:04 i think it isn't. If you ask about 0 litres - then NO. Otherwise you'll get 7 for sample input. has some new tests added? Yes, the problem is under investigation yet, and rejudge is not finished. When will these "investigations" end at last? Investigation is finished. This problem had some troubles with output format and very weak tests. Validator was fixed for this problem. Now 4.70, 4.7 and 4.7000001 are the same answers. New tests were added and Time Limit was decreased to 0.5 sec. After rejudge more than 200 submits lost AC, but about 90 WA got AC. WA3: print 5 digits after decimal point instead of 0 :) WA19: decrease EPS from 1e-8 to 1e-14 (1e-10 wasn't enough) Edited by author 29.07.2008 17:28 The set of angles ai satisfies a condition that the sum of angles in any of its nonempty subsets is not aliquot to 360 degrees. Can you prove it? I think it mean that sum of angles is not equal to 360 It is either not divisible by 360 or does not divide 360 Edited by author 29.07.2008 17:16 As i've understood none of the sets with equal number of good can be similar. But with this assumption, i've got WA1 all the time. Help! Sets 1 2 and 4 5 are dissimilar 1. First of all it seems that YES alltimes; 2. Secondly evident that we should find partition of set of all possiible multisets of products not only given K~50000; 3. Let P(i,A)- predicate for i-th subdivision of the partition. 1<=i<=N+1. Eqution P(i,A)==1 must become wrong if we add any element to A or raplace any element in A. It seems that |A| mod(N+1) has this stable property. Thanks for ur idea. At first I was suprised by your statement that the answer is always YES.. But then I saw that M>N in problem statement, that makes life a lot easier! :) My current thoughts are about assiging shops to some dedicated type of goods. Don't mind... the sets are different in problem statement :) Why did your program work so long? My algo was O(V+E) too. And I got AC with 0.001s I got ac in 0.015s,590k Just use eularian tour. I can be solved without Euler paths. Just DFS over bus routes, walking away for a side-cycle at each of its nodes if that side-route wasn't yet traversed. |
|