hdu-5738 Eureka (combination count + polar order)

Source: Internet
Author: User

Topic Links:

Eureka

Time limit:8000/4000 MS (java/others)

Memory limit:65536/65536 K (java/others)


problem DescriptionProfessor Zhang DrawsNPoints on the plane, which is conveniently labeled by1,2,.. . ,n . TheI-th Point was at(xi,yi) . Professor Zhang wants to know, the number of best sets. As the value could be very large, print it modulo9+7 .

A SetP(PContains the label of the points) is called best set if and only if there be at least one best pair inP. Numbersuandv(u,v∈P,u≠v) is called best pair, if for everyw∈P ,f(u,v)≥g(u,v,w) , whereF(U,V)=(Xu−xv) 2+ (yu−yv ) 2−−−−−−−−−−−−−−−−−−−√ andG(U,V,W)=f ( U,v ) + F (v ,w ) +f (w, U) 2 .

InputThere is multiple test cases. The first line of input contains an integerT, indicating the number of test cases. For each test case:

The first line contains an integerN (1≤n≤) -then number of points.

Each of the followingNlines contains, integersxi andyi ( −109≤x i,yi≤ 109 ) /span> --coordinates of the i-th point.

OutputFor each test case, the output of an integer denoting the answer.

Sample Input3 31 11 11 130 00 11 010 0

Sample Output430 Test Instructions: to n points, greater than or equal to 2 points on the same line can form a set, asking how many sets you have now; Idea: First give these points in the order of the coordinates, and then sequentially select a point I, the point I as a certain selection to the point inside the set, and then select the enumeration point after the point J, to form a straight line, and then see the line is not visited the point K (i<k<n&&k!=j) How many, if there are num, then you can form a set containing point I 2^num-1, at the same time these points have coincident points, there is to reduce the complexity, to use the angle of the order, but the final judgment when the angle of the accuracy of the order seems not enough, all I directly with the original coordinates to judge; AC Code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath> #include <bits/stdc++.h> #include <stack>using namespace std; #define for (i,j,n) for (int i=j;i< =n;i++) #define MST (SS,B) memset (ss,b,sizeof (ss)); typedef long LONG ll;template<class t> void Read (T&num) {C Har CH;    BOOL F=false; For (Ch=getchar (); ch< ' 0 ' | | Ch> ' 9 ';    f= ch== '-', Ch=getchar ()); for (num=0;    ch>= ' 0 ' &&ch<= ' 9 '; num=num*10+ch-' 0 ', Ch=getchar ()); F && (num=-num);}    int stk[70], tp;template<class t> inline void print (T p) {if (!p) {puts ("0"); return;}    while (p) stk[++ TP] = p%10, p/=10;    while (TP) Putchar (stk[tp--] + ' 0 '); Putchar (' \ n ');} Const LL Mod=1e9+7;const double Pi=acos ( -1.0); const int INF=1E9;CONST int N=1e5+10;const int Maxn=500+10;const double eps= 1e-9;int n,vis[1010];    LL fx,fy,f[1010];struct node{double ang; LL x, y;} Po[1010],temp[1010];int CMP1 (node A,node b) {return a.ang<B.ang;}    int CMP (node A,node b) {if (A.Y==B.Y) return a.x<b.x; return A.Y&LT;B.Y;}        int main () {int t;        Read (t);        F[0]=1;        for (i,1,1008) {f[i]=f[i-1]*2%mod;            } while (t--) {read (n);            for (i,1,n) {read (po[i].x); Read (PO[I].Y);            } sort (po+1,po+n+1,cmp);            LL ans=0;                for (i,1,n-1) {int cnt=0,s=0;                    for (J,i+1,n) {if (po[j].x==po[i].x&&po[j].y==po[i].y) {s++;continue;}                    Temp[++cnt].ang=atan2 (po[j].y-po[i].y,po[j].x-po[i].x);                    temp[cnt].x=po[j].x;                TEMP[CNT].Y=PO[J].Y;                } sort (TEMP+1,TEMP+CNT+1,CMP1);                Fx=po[i].x,fy=po[i].y;int d=0;                for (int j=1;j<=cnt;)                    {int k,num=s+1;    for (k=j+1;k<=cnt;k++)                {if ((temp[k].y-fy) * (TEMP[J].X-FX)! = (temp[j].y-fy) * (TEMP[K].X-FX)) break;                    num++;                    } j=k;                    Ans= (ans+f[num]-1+mod)%mod;                d++;            } ans= (ans-(LL) (d-1) * (f[s]-1+mod)%mod+mod)%mod;        } cout<<ans<<endl; } return 0;}

  

hdu-5738 Eureka (combination count + polar order)

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.