2017 ICPC 北京网络赛 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


【题意】


给出一系列点的坐标,问是否存在一种方案,把所有点分成A,B两类,使得无法用一条直线把这些点分成两部分,使得这两部分中的点同属于一类。


【思路】


我们先考虑特殊情况,当n<=2时,显然无法做到。


当n==3时,如果三点共线,那么可以按顺序用ABA标号即可实现,如果不共线的话,显然无法做到。


再考虑当n>3的情况,我们先对这些点求一次凸包。


若所有点均在凸包上,我们只要使其中两个相隔一个位置的点分成一类,其他均到另一类即可。


否则,凸包上的点归为一类,剩余的为一类即可。


#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define rush() int T;scanf("%d",&T);while(T--)

typedef long long ll;
const int maxn = 1005;
const ll mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;

int n,top;
char ans[maxn];

struct node
{
    double x,y;
    int pos;
    node(double x=0,double y=0,int pos=0):x(x),y(y),pos(pos) {}
}a[maxn],tu[maxn],base;

double getlen(node a,node b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

double cross(node a,node b,node c)   //a为顶点 ,叉积
{
    return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}

bool cmp(node a,node b)
{
    if(cross(base,a,b)==0)
        return getlen(base,a)<getlen(base,b);
    return cross(base,a,b)>0;
}

void get_tubao()
{
    tu[0]=a[0];
    tu[1]=a[1];
    top=1;
    for(int i=2;i<n;i++)
    {
        while(top>0&&cross(tu[top-1],tu[top],a[i])<=0)
            top--;
        tu[++top]=a[i];
    }
}

int main()
{
    rush()
    {
        scanf("%d",&n);
        base={maxn,maxn};
        int Min=0;
        for(int i=0;i<n;i++)
        {
            scanf("%lf%lf",&a[i].x,&a[i].y);
            a[i].pos=i;
            if(a[i].y<base.y||(a[i].y==base.y&&a[i].x<base.x))
            {
                base.x=a[i].x;
                base.y=a[i].y;
                Min=i;
            }
        }
        swap(a[Min],a[0]);
        sort(a+1,a+n,cmp);
        get_tubao();
        top++;                 //得到凸包上点的个数
        if(n<=2||n==3&&top==n)
        {
            puts("NO");
            continue;
        }
        puts("YES");
        for(int i=0;i<n;i++)
        {
            ans[i]='B';
        }
        ans[n]='\0';
        if(top<n)
        {
            for(int i=0;i<top;i++)
            {
                ans[tu[i].pos]='A';
            }
        }
        else
        {
            ans[tu[0].pos]='A';
            ans[tu[2].pos]='A';
        }
        puts(ans);
    }
    return 0;
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值