SPOJ UMR 10A Compute geometry

Source: Internet
Author: User

DES: Points that make up the convex polygon are given clockwise. Then there are Q queries that give the number of two points, asking the two-point line to divide the polygon into smaller portions of the area.

After each connection, the polygon is asked to calculate the area time-out. The correct solution is to find the total area of polygon by using the triangular area of the cross-spherical triangle, and to retain the prefix and the polygon. When any two points are connected, just prefix and subtract the area of a triangle.

However... What I don't understand is that the loop about Q ... for is timeout ... while is AC ... Coordinates is clearly interger...int wa...double on AC ...

#include <stdio.h>#include<string.h>#include<iostream>#include<math.h>using namespacestd;structpoint{Doublex, y;} p[50010];DoubleAREAA (Point p0, point P1, point p2)//calculates the area of triangles with vertices of these three points{    Doubletemp = (p1.x-p0.x) * (P2.Y-P0.Y)-(p2.x-p0.x) * (p1.y-p0.y); Temp/=2.0; returnfabs (temp);}Doublearea[50010];//Stores the area of the polygon's prefix polygon. intMain () {intN, Q; intxx, yy;  while(~SCANF ("%d%d", &n, &q)) { for(intI=0; i<n; ++i) {scanf ("%LF%LF", &p[i].x, &p[i].y); }        DoubleTot_area =0; area[0] =0; area[1] =0;  for(intI=1; i<n-1; ++i) {Tot_area+ = AREAA (p[0], P[i], p[i+1]); Area[i+1] =Tot_area; }        intT1, T2; Doubleans; DoubleTemp_area;  while(q--) {scanf ("%d%d", &t1, &T2); if(T2 > T1) swap (t1, T2);//Guaranteed T1>t2Temp_area = AREA[T1]-AREA[T2]-AREAA (p[0], p[t1], p[t2]); if(Temp_area < tot_area-temp_area) printf ("%.1lf\n", Temp_area); Elseprintf"%.1lf\n", tot_area-Temp_area); }    }    return 0;}
L Oh, oh, K .

Spoj UMR 10A Compute geometry

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.