Общий форумI have found two other points of square by this formula xc = (x1 + x3) / 2.0; yc = (y1 + y3) / 2.0; dx = (x3 - x1) / 2.0; dy = (y3 - y1) / 2.0; x2 = xc - dy; y2 = yc + dx; x4 = xc + dy; y4 = yc - dx; But i could not understood why this works. Then I use vector product to determine position of point etc. Can someone explain me ? This is my code on C++. The wrong is in the test №6. Why? Help me, please. #include <iostream> using namespace std; int main() { int k, n, sum=0, a, i, mas[100]; cin >> k >> n; if (k>=1 && n<=100) { for (i=0; i <= n-1; i++) { cin >> mas[i]; if (mas[i] <= 100 && mas[i] >= 0) sum = sum + mas[i]; else continue; } a = n * k; if (sum > a) cout << sum - a << endl; if (sum <= a) cout << 0 << endl; } return 0; } why is it wrong this code if (x==0 || y==0) printf ("%lld %lld",x,y); else if (x % 2 != y % 2 ) printf ("%lld %lld",y,x); else printf ("%lld %lld",x,y); test #9 crash(access violation) double..[65536] ???? who can help me?? oh....it's my code int main(void) { double number,root,temp,answer[65536]; int i=0; while(EOF!=scanf("%lf",&number)) { if(number==0) root=0; else { root=1; temp=(root+number/root)/2; while(root!=temp) { root=temp; temp=(root+number/root)/2; } } answer[i++]=root; } for(i-=1;i>=0;i--) printf("%.4lf\n",answer[i]); return 0; } double number,root,temp,answer[65536]; Size of test is not more than 256 KB. If each number consists from only one digit and there are blank spaces between numbers so no more than 131072 numbers could be in one test, not 65536. I suggest to replace "K is the maximum result" with "K is the maximum difference of gold". May I to bend the cut cylinder? Errors of calculations - reason of mistakes :) 9 !! - ввод 945 - вывод пишет wrong answer var n,i:integer; res:longint; k:string; begin read(n,k); i:=0; res:=1; if n mod length(k)=0 then repeat res:=res*(n-i); inc(i,length(k)); until n-i=length(k) else repeat res:=res*(n-i); inc(i,length(k)); until n-i=1; writeln(res); end. как решил mne toje takoy: --------------------- var x,s:string; s1,j,i,c,l:longint; begin read(x); repeat i:=i+1; s:=s+x[i]; until x[i]=' '; l:=length(x)-i; val(s,s1,c); j:=s1; repeat j:=j-l; s1:=s1*j; until j<=1; write(s1); end. On submission 4620967 a have verdict MemoryLimit, but used memory is 8954KB. #include<iostream> using namespace std; int main() { int k,n,a[1001],i,j=0,ans[1001]={0},sum; cin>>k>>n; for(i=0;i<n;i++) {cin>>a[i];} for(i=0;i<n;i++) { if((ans[i-1]+a[i])-k<=0){ans[i]=0;} else if((ans[i-1]+a[i])-k<=0 and ans[i-1]>0){ans[i]=k-a[i]+ans[i-1];} else if((ans[i-1]+a[i])-k>0 and ans[i-1]>0) {ans[i]=a[i]+ans[i-1]-k;} else if((ans[i-1]+a[i])-k>0 and ans[i-1]==0){ans[i]=a[i]-k;} }
cout<<ans[n-1]<<endl; system("pause"); return 0;} Edited by author 15.11.2012 12:40 Here some data that helps me to find a bug. 0) 4 4 1 1 3 2 - 15 1) 4 5 1 1 3 2 - 19 2) 5 4 1 1 3 2 - 19 3) 5 5 1 1 3 3 - 24 4) 3 1 1 1 3 1 - 2 5) 1 3 1 1 1 3 - 2 Give some comments plz if it helped you. =) Good luck! All your tests are working. But I'm always getting WA4... What may it be? :'( #include<stdio.h> #include<iostream> void swap(int &a, int &b) { int t=a;a=b;b=t; } void ay(int &x1,int &x2, int &x3) { if(x1>=x2&&x1>=x3) { x2=x1+(x1-x2); x3=x1+(x1-x3); return; } if(x2>=x1&&x2>=x3) { x1=x2+(x2-x1); x3=x2+(x2-x3); return; } if(x3>=x1&&x3>=x2) { x1=x3+(x3-x1); x2=x3+(x3-x2); return; } } int f(int _X1,int _X2,int _X3,int _x1,int _x2,int _x3) { int X1=_X1,X2=_X2,X3=_X3,x1=_x1,x2=_x2,x3=_x3;
if(X1==x1&&X2==x2&&X3==x3)return 0;
ay(X1,X2,X3); if(x1-X1==x2-X2&&x1-X1==x3-X3&&(x1-X1)%2==0)return 1; ay(X1,X2,X3); if(x1-X1==x2-X2&&x1-X1==x3-X3&&(x1-X1)%2==0)return 2; return -1; } void ff(int &ans, int &k1, int &k2) { if(k1!=-1&&k2!=-1&&k1+k2<ans)ans=k1+k2; } int main() { int x1,y1,x2,y2,x3,y3,X1,Y1,X2,Y2,X3,Y3,ans=30; scanf("%i %i %i %i %i %i",&x1,&y1,&x2,&y2,&x3,&y3); scanf("%i %i %i %i %i %i",&X1,&Y1,&X2,&Y2,&X3,&Y3);
int k1,k2; k1=f(X1,X2,X3,x1,x2,x3); k2=f(Y1,Y2,Y3,y1,y2,y3); ff(ans,k1,k2); k1=f(X1,X3,X2,x1,x2,x3); k2=f(Y1,Y3,Y2,y1,y2,y3); ff(ans,k1,k2); k1=f(X2,X1,X3,x1,x2,x3); k2=f(Y2,Y1,Y3,y1,y2,y3); ff(ans,k1,k2); k1=f(X2,X3,X1,x1,x2,x3); k2=f(Y2,Y3,Y1,y1,y2,y3); ff(ans,k1,k2); k1=f(X3,X1,X2,x1,x2,x3); k2=f(Y3,Y1,Y2,y1,y2,y3); ff(ans,k1,k2); k1=f(X3,X2,X1,x1,x2,x3); k2=f(Y3,Y2,Y1,y1,y2,y3); ff(ans,k1,k2);
if(ans==30)puts("IMPOSSIBLE"); else printf("%i",ans); return 0; } Thank's When I used longint I got WA11, but I changed it into int64 and got WA14. Then, I changed int64 into extended and got AC! :) how did u change it?plz write the code a:array[-1000..1000]of int64; => a:array[-1000..1000]of extended; :) can you help me for this, how can I extend in c++ long long (int 64) to a bigger type? const eps = 1e-9; var a1, b1, a2, b2, x, y, x1, y1, d, x2, y2: real; i, n: longint; Begin read(d, x1, y1, x2, y2); read(n); a1 := y1; b1 := -x1; a2 := y2; b2 := -x2; for i := 1 to n do begin read(x, y); if (abs(x1 - x2) < eps) and (abs(y1 - y2) < eps) then begin if (abs(a1 * x + b1 * y) < eps) and (x * x + y * y - eps <= d * d) and (abs(sqrt(x * x + y * y) + sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1)) - sqrt(x1 * x1 + y1 * y1)) < eps) then writeln('YES') else writeln('NO') end else if (a1 * x + b1 * y - eps <= 0) and (a2 * x + b2 * y + eps >= 0) and (x * x + y * y - eps <= d * d) then writeln('YES') else writeln('NO'); end; End. I solve this problem with type longint but it makes no difference... try this: 5 1 0 1 0 1 -1 0 corect is NO ...and it is more useful to use Longint instead of real to solve this problem. To compare distances use sqr of distances This test helped me: 1007 20 25 4 5 1 -16 -20 Answer : NO Edited by author 14.11.2012 21:28 This test helped me 5 0 1 0 1 1 0 1 correct answer: YES Please can anybody tell me what is test case #11 Instead of copying actually data, we might put a marked-number (index to copy) in the array. For example, if (x > 0) { stack[q ++] = x; } else if (x == -1) { int y = stack[q - 1]; if (y > 0) { System.out.println(y); q--; } else { y = -y; System.out.println(stack[y]); stack[q - 1] = -(y - 1); if (y == 0) { q--; } } } else { stack[q] = -(q - 1); // negative numbers mean a copy. q ++; } of course, this doesn't work for multiple continuous copy (e.g. 0, 0, 0 ..). I pursued this idea at first before I noted the easier approach based on the input constraints. The problem with storing markers representing copies in the stream is that it gets complicated when you have many combinations of partially consumed copies which are then copied, over and over again. You basically need a tree to represent the state, and the tree must be walked when popping, which takes longer. There probably is a simplified partial implementation of this, but given the constraints of the problem, it's not necessary. I agree. It gets complicated when there are copies inside copies.. so, this is not necessary because there are simpler and straightforward solutions. |
|