Hdu 5277 YJC counts stars

Source: Internet
Author: User

Hdu 5277 YJC counts stars

Test instructions
Give a plan, n points, M-bar, straight and straight edges do not intersect, to find the largest number of groups.

Limit:
1 <= N <= 1000

Ideas:
Because of the floor plan, the maximum size of the largest group is 4,m<=3*n-6;, because the straight and straight edges do not intersect.
So for answer 4, enumerate two edges;
For answer 3, enumerate one point of an edge;

/*HDU 5277 Test Instructions: Give a plan, n points, M-bar, straight and straight edges do not intersect, to find the largest number of regiment. Limit: 1 <= n <= 1000 idea: Because of the floor plan, straight and straight edges do not intersect, so the maximum size of the largest regiment is 4,m<=3*n-6; so for answer 4, enumerate two edges; for answer 3, enumerate one point of the edge; */#include &L t;iostream> #include <cstdio> #include <set> #include <cstring> #include <algorithm>using namespace std; #define MP make_pairconst int n=5000;int fr[n],to[n];int _set[n/4][n/4];bool in (int f,int t) {if (f==t) retur n false;if (f>t) swap (f,t); return _set[f][t]!=0;} bool OK (int I,int j) {if (in (Fr[i],fr[j]) && in (Fr[i],to[j]) && in (To[i],fr[j]) && in (To[i],to[j] )) return True;return false;} BOOL Vis[9000010];int get_id1 (int i,int j) {int a[4];a[0]=fr[i];a[1]=to[i];a[2]=fr[j];a[3]=to[j];sort (a,a+4); return _ SET[A[0]][A[1]]*3000+_SET[A[2]][A[3]];} int four (int m) {memset (vis,0,sizeof (VIS)), int cnt=0;for (int i=0;i<m;++i) {for (int j=i+1;j<m;++j) {if (ok (i,j)) { int Id=get_id1 (I,J); if (Vis[id]) continue;++cnt;vis[id]=1;}}} return CNT;} int get_id (int a,int b,int c) {if (a>b) swap (A, b);F (b>c) swap (b,c); int ret=_set[a][b];ret=ret*1000+c;return ret;} int three (int n,int m) {memset (vis,0,sizeof (VIS)); int cnt=0;for (int i=1;i<=n;++i) {for (int j=0;j<m;++j) {if (Fr[j] ==i | | to[j]==i) continue;//cout<<fr[j]<< ' <<i<<endl;//cout<<to[j]<< ' <<i <<endl;if (In (I,fr[j]) && in (I,to[j])) {int id=get_id (i,fr[j],to[j]);//cout<<id<<endl;if ( Vis[id]) continue;++cnt;vis[id]=1;}}} return CNT;} void Gao (int n,int m) {int ans=4;int cnt;cnt=four (m); if (CNT) {printf ("%d%d\n", ans,cnt); return;} --ans;cnt=three (n,m);//cout<<cnt<<endl;if (CNT) {printf ("%d%d\n", ans,cnt); return;} --ans;cnt=m;//cout<<cnt<<endl;if (CNT) {printf ("%d%d\n", ans,cnt); return;} printf ("%d%d\n", 1,n);} int main () {int N,m;int x,y;while (scanf ("%d%d", &n,&m)!=eof) {memset (_set,0,sizeof)); for (int _set ++i) {scanf ("%d%d", &x,&y);} for (int i=0;i<m;++i) {scanf ("%d%d", &fr[i],&to[i]), if (Fr[i]>to[i]) swap (fr[i],to[i]); _set[fr[i]][to[i]]=i+1;} Gao (n,m);} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hdu 5277 YJC counts stars

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.