ACM-ICPC(2017)北京赛区网络赛-E-Territorial Dispute(计算几何->凸包)
2017-09-25 01:08
363 查看
题目5 : Territorial Dispute
时间限制:1000ms单点时限:1000ms
内存限制:256MB
描述
In 2333, the C++ Empire and the Java Republic become the most powerful country in the world. They compete with each other in the colonizing the Mars.There are n colonies on the Mars, numbered from 1 to n. The i-th colony's location is given by a pair of integers (xi,
yi). Notice that latest technology in 2333 finds out that the surface of Mars is a two-dimensional plane, and each colony can be regarded as a
point on this plane. Each colony will be allocated to one of the two countries during the Mars Development Summit which will be held in the next month.
After all colonies are allocated, two countries must decide a border line. The Mars Development Convention of 2048 had declared that: A valid border line of two countries should be
a straight line, which makes colonies of different countries be situated on different sides of the line.
The evil Python programmer, David, notices that there may exist a plan of allocating colonies, which makes the valid border line do not exist. According to human history, this will
cause a territorial dispute, and eventually lead to war.
David wants to change the colony allocation plan secretly during the Mars Development Summit. Now he needs you to give him a specific plan of allocation which will cause a territorial dispute. He promises that he
will give you 1000000007 bitcoins for the plan.
输入
The first line of the input is an integer T, the number of the test cases (T ≤ 50).For each test case, the first line contains one integer n (1 ≤ n ≤ 100), the number of colonies.
Then n lines follow. Each line contains two integers xi, yi (0
≤ xi, yi ≤ 1000), meaning the
location of the i-th colony. There are no two colonies share the same location.
There are no more than 10 test cases with n > 10.
输出
For each test case, if there exists a plan of allocation meet David's demand, print "YES" (without quotation) in the first line, and in the next line, print a string consisting of English letters "A" and "B". Thei-th character is "A" indicates that the i-th colony was allocated to C++ Empire, and "B" indicates the Java Republic.
If there are several possible solutions, you could print just one of them.
If there is no solution, print "NO".
注意
This problem is special judged.样例输入
2 2 0 0 0 1 4 0 0 0 1 1 0 1 1
样例输出
NO YES ABBA
比赛已经结束,去题库提交。
题意:给你n个点,让你将这n个点非诚两个集合,分别为A和B,然后问你能否存在一种分配方案,使得,无论如何
画分割线都不能正好将这两个集合完全分开。
题解:随意找四个点,然后分三种情况讨论就好了。
(1)四个点共线,则ABAB就行
(2)4个点都在凸包上,则按对角线分类就好,
(3)三个点在凸包上,则让凸包上的点为A,其他为B就好啦
剩下的就是NO的情况了,很好找,n<=2 || n==3 && 这三个点不在一条直线上 为NO。
#include<set> #include<map> #include<stack> #include<queue> #include<vector> #include<string> #include<time.h> #include<math.h> #include<stdio.h> #include<iostream> #include<string.h> #include<stdlib.h> #include<algorithm> #include<functional> using namespace std; #define ll long long #define inf 1000000000 #define mod 1000000007 #define maxn 3600 #define lowbit(x) (x&-x) #define eps 1e-9 struct node { double x,y; int id; }a[maxn],st,q[maxn],b[maxn]; double cross(node a,node b,node c) { return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x); } char s[maxn]; int n; bool comp(node a,node b) { if(cross(a,b,st)>0) return 1; if(cross(a,b,st)==0 && fabs(a.x-st.x)<fabs(b.x-st.x)) return 1; return 0; } int main(void) { double ans=0; int i,top,T; scanf("%d",&T); while(T--) { memset(s,'\0',sizeof(s)); scanf("%d",&n); st.x=st.y=10000000; for(i=1;i<=n;i++) { scanf("%lf%lf",&a[i].x,&a[i].y); if(a[i].y<st.y || a[i].y==st.y && a[i].x<st.x) st=a[i]; a[i].id=i; } sort(a+1,a+n+1,comp); q[1]=a[1];q[2]=a[2];top=2; for(i=3;i<=n;i++) { while(top>1 && cross(q[top-1],a[i],q[top])>=0) top--; q[++top]=a[i]; } if(n<3 || n==3 && top==3) { printf("NO\n"); continue; } printf("YES\n"); if(top<n) { for(i=1;i<=top;i++) s[q[i].id]='A'; for(i=1;i<=n;i++) { if(s[a[i].id]!='A' && s[a[i].id]!='B') s[a[i].id]='B'; } } else { s[a[1].id]='A'; s[a[2].id]='B'; s[a[3].id]='A'; for(i=4;i<=n;i++) s[a[i].id]='B'; } printf("%s\n",s+1); } return 0; }
相关文章推荐
- 【分类讨论】【计算几何】【凸包】hihocoder 1582 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E. Territorial Dispute
- 【计算几何】【圆反演】计蒜客17314 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 G. Finding the Radius for an Inserted Circle
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 I GSM Base Station Identification(暴力,计算几何)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 GSM Base Station Identification 线性变换||计算几何
- #1582 : Territorial Dispute ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 (求凸包)
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 Territorial Dispute (凸包)
- HDU 4449 Building Design 第37届ACM/ICPC 金华赛区H题 (计算几何,三维凸包+空间坐标旋转+二维凸包)
- 2017 ACM-ICPC乌鲁木齐网络赛 B. Out-out-control cars【计算几何||判断射线与线段是否相交】
- ACM-ICPC北京赛区2017网络同步赛 (题目6 : Secret Poems)
- 2017 ACM-ICPC 亚洲区(北京赛区)网络赛 - A I
- 2017 ACM-ICPC 亚洲区(北京赛区)网络赛C.Matrix (DP)
- hihoCoder - 1578 Visiting Peking University (2017 ACM-ICPC 亚洲区 (北京赛区) 网络赛 A)
- ACM-ICPC北京赛区2017网络同步赛 题目6 : Secret Poems
- ACM-ICPC北京赛区2017网络同步赛 题目5 : Cats and Fish【模拟】
- hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
- 周末训练笔记+ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛+2017 ACM-ICPC 亚洲区(南宁赛区)网络赛(9.23,9.24)
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E.Territorial Dispute(凸包)
- hihoCoder - 1586 Minimum (2017 ACM-ICPC 亚洲区 (北京赛区) 网络赛 I)
- hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
- 2017acm/icpc北京赛区网络赛 Agent Communication 二分+搜索