ACM-ICPC(2017)北京赛区网络赛-E-Territorial Dispute(计算几何->凸包)
来源:互联网 发布:怎么修复excel软件 编辑:程序博客网 时间:2024/05/22 17:05
题目5 : Territorial Dispute
- 样例输入
220 00 140 00 11 01 1
- 样例输出
NOYESABBA
描述
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". The i-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.
比赛已经结束,去题库提交。
题意:给你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-9struct 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; }
- ACM-ICPC(2017)北京赛区网络赛-E-Territorial Dispute(计算几何->凸包)
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E Territorial Dispute (凸包)
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E.Territorial Dispute(凸包)
- 2017ICPC北京赛区网络赛 E Territorial Dispute(计算几何)
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 Territorial Dispute (凸包)
- hihocoder 1582 : Territorial Dispute (计算几何 凸包)(2017 北京网络赛E)
- hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E.Territorial Dispute
- #1582 : Territorial Dispute ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 (求凸包)
- 2017 ICPC 北京网络赛 Territorial Dispute 【凸包】
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题解汇总 Territorial Dispute
- hihocoder 1582 territorial dispute(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
- 2017北京网络赛 && hihocoder 1582 Territorial Dispute(凸包)
- 2017icpc北京赛区网络赛E题(计算几何)
- 2017北京网赛hihocoder #1582 : Territorial Dispute 【凸包】
- ICPC2017网络赛(北京)Territorial Dispute(凸包分割)
- ACM-ICPC北京赛区2015网络同步赛E:Stamps
- 2017 ACM-ICPC 亚洲区(北京赛区)网络赛
- YYCache源码分析(三)
- 详解Hadoop核心架构
- oos 文件下载
- 基于Dubbo的分布式系统架构(三):安装dubbo监控中心
- leetcode 17. Letter Combinations of a Phone Number
- ACM-ICPC(2017)北京赛区网络赛-E-Territorial Dispute(计算几何->凸包)
- 调整数组顺序使奇数位于偶数前面
- NodeManager代码分析之NodeManager启动过程
- Redis学习02——Jedis使用
- mybatis入门基础(十)-----分页查询
- 算法练习(3)—— 栈
- 求排列的逆序数
- struts2写web层的项目,页面显示总是路径更改不了。或是路径改了,但效果运行不出来。【双清:ctrl+shift+delete清浏览器缓存;Tomcat 右键clean,清理Tomcat缓存。】
- wr720n v4 折腾笔记(三):网络配置与扩充USB