Bzoj1913[apio2010]signaling Signal Overlay Computational geometry

Source: Internet
Author: User

1913: [Apio2010]signaling signal coverage time limit:20 Sec Memory limit:64 MB
submit:1583 solved:646
[Submit] [Status] [Discuss] Descriptioninput input The first line contains a positive integer n, which represents the total number of houses. Next there are n lines, each representing the location of each house. For i = 1, 2, ..., n, the coordinates of the I house are represented by a pair of integers xi and Yi, separated by a space between them. The output file contains a real number that indicates how many houses are covered by the signal, and the absolute error between the output and the exact value must be guaranteed to be no more than 0.01. Sample Input4
0 2
4 4
0 0
2 0Sample Output3.500HINT

3.5, 3.50, 3.500, ... Any one of the outputs is correct. In addition, 3.49, 3.51, 
3.499999, ... And so on are also acceptable outputs.  
data range  
100% data Guarantee, for i = 1, 2, ..., n, the coordinates of the I House (xi, Yi) are integers and  
–1,000,000≤xi, yi≤1,000,000. ren What three houses are not in the same line, any four houses are not
on the same circle;  
40% data, n≤100; 
70% data, n≤500; 
100% data, 3≤n≤1,500.  

Test instructions is to ask for the choice of three points around a circle, the circle contains the desired number of points
can be obtained by SUM/C (n,3), then it is required that sum is the sum of any three dots that make up the number of the circle containing points
The violent enumeration is certainly not.

I understand:
for any one three-point circle, if it contains some points, then these three points and any point contained therein can form a quadrilateral


So looking for the number of quadrilateral can be, the key is to each quadrilateral as three points to form a circle + An answer to a point within a circle

Convex quadrilateral number s2 bad processing, can deal with the number of concave quadrilateral S1, s1+s2=c (n,4) can calculate s2

Dealing with concave quadrilateral, with total number of quadrilateral-convex number
Enumerate each point as a point inside the concave quadrilateral and consider another three points:
If a concave quadrilateral is to be formed, then there must be an angle of two edges greater than 180, enumerate each point, and find its next target point (with the angle greater than 180 degrees) calculated.

1#include <bits/stdc++.h>2 #definell Long Long3 #defineN 15054 using namespacestd;5 intn,tp;ll s1,s2;6 structp{7     intx, y;Doubleang;8Poperator- (ConstP &b)Const{returnP {x-b.x,y-b.y};}9     BOOL operator< (ConstP &b)Const{returnang<B.ang;}Ten }a[n],q[n]; Onell CRS (P a,p b) {return(LL) a.x*b.y-(LL) a.y*b.x;} All solve (intx) { -tp=0; -ll all=1ll* (n1) * (n2) * (n3)/6; the      for(intI=1; i<=n;i++){ -         if(i==x) q[0]=A[i]; -         Elseq[++tp]=A[i]; -     } +      for(intI=1; i<=tp;i++){ -P tmp=q[i]-q[0]; +q[i].ang=atan2 (tmp.y,tmp.x); A     } atSort (q+1, q+1+tp); -     intp=2, cnt=0; -      for(intI=1; i<=tp;i++){ -          while(CRS (q[i]-q[0],q[p]-q[0]) >=0){ -p=p%tp+1; cnt++; -             if(p==i) Break; in         } -all-=cnt* (cnt-1)/2; cnt--; to     } +     returnAll ; - } the intMain () { *scanf"%d",&n); $     if(n==3) {puts ("3.00");return 0;}Panax Notoginseng      for(intI=1; i<=n;i++) -scanf"%d%d",&a[i].x,&a[i].y); the      for(intI=1; i<=n;i++) s1+=solve (i); +s2=1ll*n* (n1) * (n2) * (n3)/ --S1; A     Doubleans=2*s2+s1;ans/=1ll*n* (n1) * (n2)/6; theprintf"%.6LF", ans+3); +     return 0; -}

Bzoj1913[apio2010]signaling Signal Overlay Computational 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.