ICPC2017网络赛(北京)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类,使得无法用一条直线分隔开这些点,输出YES即每个点放在A类还是B类(任意分)。如果做不到,就printf(“NO\n”);


对于大于三个点时,跑一遍凸包。

如果凸包点个数==n;说明所有点都在凸包边上,选择两个不相邻的点归为一类即可。

如果凸包点个数<n;说明是凸包多边形里面包着一些点。直接把边归为一类,里面的另一类。


n==3是特判是不是直线。

n<3时全NO

【代码】:

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
struct point{
    double x,y;
    int i;
}p[1100],stk[1100],base;
int n,top;
double lenth(point a,point b)
{
    return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}
double across(point c,point m,point n)//求叉乘
{
    return (m.x-c.x)*(n.y-c.y)-(m.y-c.y)*(n.x-c.x);
}
bool cmp(point p1,point p2)
{
    if(across(base,p1,p2)==0)//三点一线
        return lenth(base,p1)<lenth(base,p2);//按距离从近到远
    return across(base,p1,p2)>0;
}
void getside()//求凸包点,存入数组stk[]
{
    stk[0]=p[0];
    stk[1]=p[1];
    top=1;//top始终表示上一个确定下来的点
    for(int i=2;i<n;i++)
    {
        while(top>0&&across(stk[top-1],stk[top],p[i])<=0)//上一个确定的点是凹的
            top--;
        stk[++top]=p[i];
    }
}
char s[1010];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        base={1000,1000};
        int mini=0;
        for(int i=0;i<n;i++)
        {
            scanf("%lf%lf",&p[i].x,&p[i].y);
            p[i].i=i;
            if(p[i].y<base.y||(p[i].y==base.y&&p[i].x<base.x))
            {
                base.x=p[i].x;
                base.y=p[i].y;
                mini=i;
            }
        }
        swap(p[mini],p[0]);
        sort(p+1,p+n,cmp);//排序
        getside();//得出凸包点
        if(n<=2 || n==3&&top+1==n)
            puts("NO");
        else
        {
            for(int i=0;i<120;i++)s[i]='B';
            s[n]=0;
            puts("YES");
            if(top+1<n)
            {
                for(int i=0;i<=top;i++)
                    s[stk[i].i]='A';
            }
            else if(top+1==n)
            {
                s[stk[0].i]='A';
                s[stk[2].i]='A';
            }
            puts(s);
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雪的期许

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值