L. chopping time limit:1000msmemory limit:65536kb64-bit integer IO format:%lldJava class Name:MainSubmitstatus pid:29379
In the film, we can often see the samurai pull out the knife, and then a knife down, the result ... ....... ....... ......... A piece of paper was cut in half, and it was embarrassing ...
In the subject, we need to calculate the area of the smaller part that was chopped down.
We assume that the paper is rectangular, parallel to the axis, and that the warrior's path to chop the paper is a straight line.
Input
The first line is an integer N (2<=n<=350) that represents the number of data groups.
Next line, 7 integers per line, xl,yl,xr,yr,a,b,c, table represents the rectangle's lower-left coordinate (xl,yl), the upper-right coordinate (xr,yr), and the trajectory equation ax+by+c=0. The absolute value of integers is less than 200.
Output
For each set of data, output a three-bit decimal that represents the area of the smaller portion of the cut. The data guarantees that the area is greater than 0.001.
Sample Input
31 1 3 3-1 1 01 1 3 4-1 1 01 2 3 4-1 1 0
Sample Output
2.0002.0000.500 | |
Idea: The rectangle has four edges that extend---|----------|----------
| |
------|----------|------------
The line ax+by+c=0 has four intersections with it,
Find out four intersection of the total which two is on the rectangle can forget (at that time little yellow think of the method and this difference I listened to 1 hours did not understand I do not want to write)
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include < Math.h>using namespace Std;int t;int main () {int t; scanf ("%d", &t); while (t--) {double s,s; Double x1,y1,x2,y2,a,b,c; Double xy1,xy2,x1y,x2y; scanf ("%lf%lf%lf%lf", &x1,&y1,&x2,&y2); scanf ("%lf%lf%lf", &a,&b,&c); xy1= (c+b*y1) *1.0/-a;//bottom point xy2= (c+b*y2) *1.0/-a;//top point x1y= (c+a*x1) *1.0/-b;//left point x2y= (c+a*x2) *1.0/-b;//right Side Point//cout<<xy1<< "<<Xy2<<" "<<x1Y<<" "<<x2Y<<endl; BOOL f1,f2,f3,f4;//judged on that side f1= (xy1>=x1) && (XY1<=X2); F2= (xy2>=x1) && (XY2<=X2); f3= (x1y>=y1) && (x1y<=y2); f4= (x2y>=y1) && (x2y<=y2); /* trapezoid area */if (F1&&F2)//Bottom parallel Edge {s= (xy1+xy2-2*x1) * (Y2-Y1)/2.0; } else if (F3&&F4)///left and right parallel edges {s= (x1y+x2y-2*y1) * (x2-x1)/2.0;/**/}/* Triangle Area */else if (F1&&F3)//lower left intersect edge { s= (xy1-x1) * (X1Y-Y1)/2.0; } else if (F1&&F4)//lower right intersect side {s= (x2-xy1) * (X2Y-Y1)/2.0; } else if (F2&&F3)//upper left intersect side {s= (xy2-x1) * (Y2-X1Y)/2.0; } else if (F2&&F4)//upper right intersect edge {s= (x2-xy2) * (Y2-X2Y)/2.0; } s=fabs (y2-y1) * (X2-X1); S=min (s,s-s); printf ("%.3lf\n", s); }}
BNU chop (Super flood problem)