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 coloniesof 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.
2 2 0 0 0 1 4 0 0 0 1 1 0 1 1样例输出
NO YES
ABBA
一直在水这个题,最后没时间了,还是没A到,其实想明白了的话,题目很简单的。
总的来说,就是给你N个点,这些点可以标记为A或者B,你是否有一种标记方法使得无法用一条直线来划分A和B,也就是无法使直线两边分别为A和B。
首先一个点,两个点都无法得到这样的直线,三个点的时候,若三点不共线,也无法得到,但如果三点共线就可以得到这样的点,即ABA或BAB,此时要根据距离标记。当N大于等于4时,肯定有解。不妨做一个凸包,把凸包上的点全部标记为A,凸包内的点全部标记为B。若是所有的点都在凸包上,那么只需要隔标记第一个点跟第三个点为A就可以。最后输出答案。
代码实现:
#include
#include
#include
#include
#include
#include
#define ll long long
#define mset(a,x) memset(a,x,sizeof(a))
using namespace std;
const double PI=acos(-1);
const int inf=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1005;
const int mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
struct point{
int x,y;
int index;
}p[1005],ans[1005],temp;
int n,top,visit[maxn]; //top记录凸包上的点,visit作为标记,1代表A,0代表B
double across(point a,point b,point c) //叉乘
{
return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
}
double dis(point a,point b) //三点共线,求距离
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int cmp(point a,point b) //排序函数
{
if(!across(temp,a,b))
{
if(dis(temp,a)0)
return 1;
else
return 0;
}
void solve() //得到凸包
{
int i,j,k;
top=1;
ans[0]=p[0];
ans[1]=p[1];
for(i=2;i0&&across(ans[top-1],ans[top],p[i])<=0)
top--;
ans[++top]=p[i];
}
}
int main()
{
int i,j,k,t,cnt;
cin>>t;
while(t--)
{
cin>>n;
cnt=0;
temp.x=1005;
temp.y=1005;
mset(visit,0);
for(i=0;i>p[i].x>>p[i].y;
p[i].index=i;
if(p[i].y