标签:secret ica string 三角形 view its exist comm sha
#1582 : 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 ofdifferent 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.
- 样例输入
2 2 0 0 0 1 4 0 0 0 1 1 0 1 1- 样例输出
NO YES ABBA
题目链接:
http://hihocoder.com/problemset/problem/1582
题目大意:
一个二维平面,上面有一些点,问是否存在01染色方案,使得0和1的点无法被一条直线区分开。
题目思路:
【凸包】
一开始题目看错了以为是沿着网格的边的折线。。
首先可以知道n>3时只要满足存在两条线段,一条以2个0为端点,一条以2个1为端点,这两条线段相交即可
n=3时三角形无解,共线时中间的点为0,端点为1即可。
n=2或者1时无解。
可以求个凸包,然后判断,如果有节点不在凸包上,那么必有解,将不在凸包的点染为1,在的为0,即可。
如果节点全在凸包上,若n>3,则取不相邻的两个节点染为1,其余为0即可。否则无解。
1 /**************************************************** 2 3 Author : Coolxxx 4 Copyright 2017 by Coolxxx. All rights reserved. 5 BLOG : http://blog.csdn.net/u010568270 6 7 ****************************************************/ 8 #include<bits/stdc++.h> 9 #pragma comment(linker,"/STACK:1024000000,1024000000") 10 #define abs(a) ((a)>0?(a):(-(a))) 11 #define lowbit(a) (a&(-a)) 12 #define sqr(a) ((a)*(a)) 13 #define mem(a,b) memset(a,b,sizeof(a)) 14 const double EPS=0.00001; 15 const int J=10; 16 const int MOD=1000000007; 17 const int MAX=0x7f7f7f7f; 18 const double PI=3.14159265358979323; 19 const int N=104; 20 using namespace std; 21 typedef long long LL; 22 double anss; 23 LL aans; 24 int cas,cass; 25 int n,m,lll,ans; 26 bool mark[N]; 27 class xxx 28 { 29 public: 30 int x,y,num; 31 xxx(){} 32 xxx(int x,int y) 33 { 34 this->x=x; 35 this->y=y; 36 } 37 int dis() 38 { 39 return sqr(x)+sqr(y); 40 } 41 int dis(xxx aa) 42 { 43 return sqr(x-aa.x)+sqr(y-aa.y); 44 } 45 xxx operator - (const xxx &bb) 46 { 47 return xxx(this->x-bb.x,this->y-bb.y); 48 } 49 }a[N],s[N]; 50 int Cross(xxx aa,xxx bb) 51 { 52 return aa.x*bb.y-aa.y*bb.x; 53 } 54 int Cross(xxx aa,xxx bb,xxx cc) 55 { 56 return Cross(bb-aa,cc-aa); 57 } 58 bool cmp1(xxx aa,xxx bb) 59 { 60 return aa.y!=bb.y?aa.y<bb.y:aa.x<bb.x; 61 } 62 bool cmp(xxx aa,xxx bb) 63 { 64 return Cross(a[1],aa,bb)!=0?(Cross(a[1],aa,bb)>0):(aa.dis(a[1])<bb.dis(a[1])); 65 } 66 bool judge() 67 { 68 int i; 69 if(lll<n) 70 { 71 for(i=1;i<=lll;i++) 72 mark[s[i].num]=1; 73 return 1; 74 } 75 else if(n>3) 76 { 77 mark[s[1].num]=mark[s[3].num]=1; 78 return 1; 79 } 80 else return 0; 81 } 82 int main() 83 { 84 #ifndef ONLINE_JUDGE 85 freopen("1.txt","r",stdin); 86 // freopen("2.txt","w",stdout); 87 #endif 88 int i,j,k; 89 int x,y,z; 90 for(scanf("%d",&cass);cass;cass--) 91 // init(); 92 // for(scanf("%d",&cas),cass=1;cass<=cas;cass++) 93 // while(~scanf("%d",&n)) 94 { 95 mem(mark,0);lll=0; 96 scanf("%d",&n); 97 for(i=1;i<=n;i++) 98 { 99 scanf("%d%d",&a[i].x,&a[i].y); 100 a[i].num=i; 101 } 102 sort(a+1,a+1+n,cmp1); 103 sort(a+2,a+1+n,cmp); 104 for(i=1;i<=n;i++) 105 { 106 while(lll>1 && Cross(s[lll-1],a[i],s[lll])>=0) 107 lll--; 108 s[++lll]=a[i]; 109 } 110 111 for(i=1;i<=lll;i++)s[i+lll]=s[i]; 112 for(i=2,j=1;i<=lll;i++) 113 if(s[i].num<s[j].num)j=i; 114 for(i=j;i<j+lll;i++) 115 printf("%d ",s[i].num); 116 puts(""); 117 118 if(judge()) 119 { 120 puts("YES"); 121 for(i=1;i<=n;i++) 122 printf("%c",mark[i]?‘A‘:‘B‘); 123 puts(""); 124 } 125 else puts("NO"); 126 } 127 return 0; 128 } 129 /* 130 // 131 132 // 133 */
hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
标签:secret ica string 三角形 view its exist comm sha
原文地址:http://www.cnblogs.com/Coolxxx/p/7619964.html