Try to check situation, when rectangles touch and when rectangles don't have intersection. 2 -1 -2 0 0 2 0 -2 OUT 1 10 0 5 10 10 8 3 3 OUT 5 unsigned is enough: template <typename T, typename G> void psort(T& a, T& b, T& c, T& d, G gt){ if(gt(a, b)) swap(a, b); if(gt(c, d)) swap(c, d); if(gt(a, c)){ swap(a, c); swap(b, d); } } inline unsigned intersection_length(int a, int b, int c, int d){ psort(a, b, c, d, greater<int>()); if(c > b){ cout << 0 << endl; exit(0); } return min(b, d) - c; } Have anybogy gotten? I shocked... when I input/output like this ... scanf("%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d", &x01, &y01, &x1, &y1, &x02, &y02, &x2, &y2); ... printf("%I64d", intersect); ... I got WA#17, and when I instead of that wrote this ... cin>>x01>>y01>>x1>>y1>>x02>>y02>>x2>>y2; ... cout<<intersect; ... I got AC! Why? Doesn't the "scanf" correctly read __int64 numbers? P.S. Sorry for my english. i used scanf. it works scanf("%I64d%I64d\n%I64d%I64d\n%I64d%I64d\n%I64d%I64d", &x11,&y11, &x12,&y12, &x21,&y21, &x22,&y22); I tried scanf with "\n" -- the same verdict: WA#17 Edited by author 12.04.2010 23:46 if all of x01, y01, x1, y1, x02, y02, x2, y2 are 64bit integers (long long or __int64) then i don't know. strange.. May be your "intersection" variable either float or double but you print it like 64-bit integer. Try this: printf("%lld", intersect); May be your "intersection" variable either float or double but you print it like 64-bit integer. Try this: printf("%lld", intersect); It gets WA#1. All of variables x01, y01, x1, y1, x02, y02, x2, y2, intersect, have type "long long", so output by printf("%I64d", intersect); must be correct, but it isn't so. Edited by author 14.04.2010 01:06 Edited by author 14.04.2010 01:07If you want, I can send my code on your e-mail, if you got AC, and you will be able to check this phenomenon. that would be interesting to look at it. accdead@gmail.com I also got WA#17 I don't know what to do Give me some tests please or tell what in my code is wrong #include <iostream> using namespace std; struct Coord { __int64 x; __int64 y; }; bool Sign(__int64 x, __int64 y) { if(x > y) return 1; return 0; } void Sort(Coord* arr) { for(int i = 0; i < 4; i++) { for(int j = i; j < 4; j++) { if((arr[j].x < arr[i].x) || (arr[j].x == arr[i].x && arr[j].y > arr[i].y)) { Coord tmp = arr[j]; arr[j] = arr[i]; arr[i] = tmp; } } } } int main() { Coord crd[4]; for(int i = 0; i < 4; i++) { cin >> crd[i].x >> crd[i].y; } bool sign1 = Sign(crd[0].x, crd[1].x) ^ Sign(crd[0].y, crd[1].y); bool sign2 = Sign(crd[2].x, crd[3].x) ^ Sign(crd[2].y, crd[3].y); __int64 a = -1, b = -1; Coord arr[4]; for(int i = 0; i < 4; i++) { arr[i].x = crd[i].x; if(i < 2) arr[i].y = 0; else arr[i].y = 1; if(i % 2 == 1) { if(arr[i].x < arr[i-1].x) { __int64 tmp = arr[i].x; arr[i].x = arr[i-1].x; arr[i-1].x = tmp; } } } Sort(arr); if(arr[2].y == arr[0].y || arr[2].y == arr[1].y || arr[2].x == arr[0].x || arr[3].x == arr[1].x) a = arr[2].x - arr[1].x; for(int i = 0; i < 4; i++) { arr[i].x = crd[i].y; if(i < 2) arr[i].y = 0; else arr[i].y = 1; if(i % 2 == 1) { if(arr[i].x < arr[i-1].x) { __int64 tmp = arr[i].x; arr[i].x = arr[i-1].x; arr[i-1].x = tmp; } } } Sort(arr); if(arr[2].y == arr[0].y || arr[2].y == arr[1].y || arr[2].x == arr[0].x || arr[3].x == arr[1].x) b = arr[2].x - arr[1].x; if(sign1 == sign2) { cout << a + b << endl; } else { if(a == -1 || b == -1) cout << 0 << endl; if(a > b) cout << a << endl; else cout << b << endl; } return 0; } It is the first test where rectangle projections do not intersect. I got WA #41, can anyone give me some test case ? Thank you :) I got WA6 in this case: if (inc1 == inc2) { cout << labs(cr2x - cr1x) + labs(cr2y - cr1y); return; } cout << max(labs(cr2x - cr1x), labs(cr2y - cr1y)); but I got AC in this case: if (inc1 == inc2) { cout << (cr2x - cr1x) + labs(cr2y - cr1y); return; } cout << max(labs(cr2x - cr1x), labs(cr2y - cr1y)); and in this case: if (inc1 == inc2) { cout << labs(cr2x - cr1x) + (cr2y - cr1y); return; } cout << max(labs(cr2x - cr1x), labs(cr2y - cr1y)); and in this: if (inc1 == inc2) { cout << (cr2x - cr1x) + (cr2y - cr1y); return; } cout << max(labs(cr2x - cr1x), labs(cr2y - cr1y)); p.s. cr1x, cr1y, cr2x, cr2y is long long, (cr2x - cr1x)>=0 and (cr2y - cr1y)>=0 always, but why in this case does not labs() work correctly ? Letter 'l' in "labs" stands for "long" = "int" (not "long long"). So in the first case two summands are converted from "long long" to "int" and the summation causes overflow. In the second and the third cases one of the summands has type "long long" so the sum is in type "long long" too. Edited by author 12.04.2010 22:11 2 -1 -2 0 0 2 0 -2 answer: 1 Sorry, but get tired of it. Are there any suggestions, what checks test #3? > each street stretches through the whole city either from west to east or from north to south. Do these directions have any influence? I have same problem my code is #include <iostream> #include <math.h> using namespace std; int main() { int x[2],y[2],a[2],b[2]; cin>>x[0]>>x[1]>>y[0]>>y[1]>>a[0]>>a[1]>>b[0]>>b[1]; double e=((y[0]-x[0])*(y[0]-x[0])); double t=((y[1]-x[1])*(y[1]-x[1])); double u=e+t; double qq=sqrt(u); double ww=sqrt(qq); double ee=((b[0]-a[0])*(b[0]-a[0])); double tt=((b[1]-a[1])*(b[1]-a[1])); double uu=ee+tt; double qqq=sqrt(uu); double www=sqrt(qqq); double iga=ceil((www+ww)/2); cout<<iga; return 0; } what to do?help please..... 1 1 5 5 2 2 4 4 output should be 4, i think. your program gives 3. My algorithms is: make 2 rectangles first with points Dr Dee House and St Paul Cathedral second with points Gallery and Museum next find rectangle which is the intersection of the first 2. the result is width + height of the last rectangle. but still WA on test 3 1 1 5 5 2 4 4 2 output should be 2, i think. your algorythm gives 4 yeah, the algorithm is wrong I changed it and now WA on test #6 yep. the same. 1) 0 0 6 2 0 0 6 2 == 8 2) 0 0 6 2 0 2 6 0 == 6 3) 0 0 2 6 0 6 2 0 == 6 thank you. now i understand... Edited by author 12.04.2010 15:34 Edited by author 12.04.2010 15:34 I output some debug info to cerr and get WA1. I think it is something wrong with a system. |
|