BNU chop (Super flood problem)

Source: Internet
Author: User
Tags chop

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.000

0.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&LT;=X2);        F2= (xy2>=x1) && (XY2&LT;=X2);        f3= (x1y>=y1) && (x1y<=y2);        f4= (x2y>=y1) && (x2y<=y2);        /* trapezoid area */if (F1&AMP;&AMP;F2)//Bottom parallel Edge {s= (xy1+xy2-2*x1) * (Y2-Y1)/2.0; } else if (F3&AMP;&AMP;F4)///left and right parallel edges       {s= (x1y+x2y-2*y1) * (x2-x1)/2.0;/**/}/* Triangle Area */else if (F1&AMP;&AMP;F3)//lower left intersect edge {        s= (xy1-x1) * (X1Y-Y1)/2.0;        } else if (F1&AMP;&AMP;F4)//lower right intersect side {s= (x2-xy1) * (X2Y-Y1)/2.0;        } else if (F2&AMP;&AMP;F3)//upper left intersect side {s= (xy2-x1) * (Y2-X1Y)/2.0;        } else if (F2&AMP;&AMP;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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.