Hdu 5277 YJC Counts stars violence

Source: Internet
Author: User

YJC counts stars

Time Limit:20 Sec

Memory limit:256 MB

Topic Connection

http://acm.hdu.edu.cn/showproblem.php?pid=5277

Description

YJC is an old train driver. One night, he looked up at the sky, the stars bright, he suddenly felt that the sky is like a plane, and every star, is a point in the plane.
He numbered these points at 1 to N. These points meet any three-point non-collinear line. He connects some points with line segments, but any two segments do not intersect outside the endpoints. If any two points in a set of points have a segment that is directly connected, it is called a dujiao point set. He wants you to find the maximum Dujiao point set size and the maximum number of Dujiao point sets.

Input

Multiple sets of tests.
For each group of data:
The first line, two integer n,m, represents the number of points and segments.
The next n rows are two integers per line, x, Y, which represents the coordinates of the first point.
The next m line is two integers per line u,v, representing a segment connecting U and v.

Output

For each set of data output, two integers separated by spaces represent the largest Dujiao point set size and the maximum number of Dujiao point sets.

Sample Input

2 1
1 1
2 2
1 2
3 3
1 1
2 2
4 5
1 2
2 3
3 1

Sample Output

2 1
3 1

HINT

1≤n≤1000−109≤x,y≤109 1≤t≤5 (T is the number of data groups)
Guaranteed not the same point and the same edge, nor the u=v situation

Test instructions

Exercises

First of all, we put forward the problem of the data range of M, in fact, for the plan is m≤3n−6 ...
The first five points of the group is the plan to determine the K5, including the sub-figure K5 is not a plan. So the answer can only be 4.
So how do we count the answers?
The brute force enumerates the first point, then enumerates the second point, enumerates the third, fourth, and requires each point to be connected to the other points above. You'll find it's over, why?
Enumeration The first point is O (n), the second point of enumeration is O (N2), but note m=o (n), so the enumeration of the third point only O (n) times, the total number is O (N2). Notice that the number of ternary rings in the plan is O (n), because the adjacent points of a point are sorted by a few angles, then the edges of the points are equivalent to several intervals, and the intervals do not intersect, so the total is ∑degi=o (m) (Degi for degrees). The number of times the fourth point is enumerated is also O (n), and the total complexity is O (N2). It was enough for n=1000 to come.

Code

#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineTest Freopen ("Test.txt", "R", stdin)#defineMAXN 1005#defineMoD 10007#defineEPS 1e-9Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//**************************************************************************************structnode{intx, y;}; Node A[MAXN];intG[maxn][maxn];vector<int>G[MAXN];intOne,two,three,four;intn,m;voidinit () { One=two=three=four=0; Memset (A,0,sizeof(a)); Memset (g,0,sizeof(g));  for(intI=0; i<n;i++) G[i].clear ();}intMain () { while(SCANF ("%d%d", &n,&m)! =EOF)        {init ();  for(intI=0; i<n;i++) a[i].x=read (), a[i].y=read ();  for(intI=1; i<=m;i++)        {            intX=read (), y=read (); X--, y--; G[x][y]=g[y][x]=1;            G[x].push_back (y);        G[y].push_back (x); }         for(intI=0; i<n;i++)        {             for(intj=0; J<g[i].size (); j + +)            {                 for(intk=0; K<g[i].size (); k++)                {                    if(g[i][j]!=g[i][k]&&G[g[i][j]][g[i][k]]) {Three++;  for(intt=0; T<g[i].size (); t++)                        {                            if(g[i][j]!=g[i][k]&&g[i][j]!=g[i][t]&&g[i][k]!=g[i][t]&&g[g[i][j]][g[i][k]]&&g[ g[i][j]][g[i][t]]&&G[g[i][k]][g[i][t]]) { Four++; }                        }                    }                }            }        }        if(four) cout<<"4"<<four/ -<<Endl; Else if(three) cout<<"3"<<three/6<<Endl; Else if(m) cout<<"2"<<m<<Endl; Elsecout<<"1"<<n<<Endl; }}

Hdu 5277 YJC Counts stars violence

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.