Territorial Dispute(2017 ACM/ICPC Asia Regional Beijing Online)

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.

Input

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.

Output

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”.

Sample Input

2
2
0 0
0 1
4
0 0
0 1
1 0
1 1

Sample Output

NO
YES
ABBA

题意:

给出n个点,问能否给所有点分成两类,使得无法画一条线分隔开两类点。

思路:

首先考虑1≤n<3时,肯定无法满足需求,输出NO。
当n==3时,如果三点不共线,则一定不满足,输出NO。
当n>3时,求这些点的凸包,如果凸包的点数等于n,那么任意挑两个相邻点取不同值即可;否则如果小于n,则把凸包上的点和其他点各自分为两类。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <stack>
#include <cstring>
#include <queue>
#include <list>
#include <stdio.h>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include <iterator>
#include <functional>
#include <stdlib.h>
#include <time.h>
#include <bitset>
using namespace std;

#define pi acos(-1)
#define s_1(x) scanf("%d",&x)
#define s_2(x,y) scanf("%d%d",&x,&y)
#define s_3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define s_4(x,y,z,X) scanf("%d%d%d%d",&x,&y,&z,&X)
#define s_5(x,y,z,X,Y) scanf("%d%d%d%d%d",&x,&y,&z,&X,&Y)
#define S_1(x) scan_d(x)
#define S_2(x,y) scan_d(x),scan_d(y)
#define S_3(x,y,z) scan_d(x),scan_d(y),scan_d(z)
#define PI acos(-1)
#define endl '\n'
#define srand() srand(time(0));
#define me(x,y) memset(x,y,sizeof(x));
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define close() ios::sync_with_stdio(0); cin.tie(0);
#define FOR(x,n,i) for(int i=x;i<=n;i++)
#define FOr(x,n,i) for(int i=x;i<n;i++)
#define fOR(n,x,i) for(int i=n;i>=x;i--)
#define fOr(n,x,i) for(int i=n;i>x;i--)
#define W while
#define sgn(x) ((x) < 0 ? -1 : (x) > 0)
#define bug printf("***********\n");
#define db double
#define ll long long
#define mp make_pair
#define pb push_back

#define retrun return
#define ture true
typedef long long LL;
typedef pair <int, int> ii;
const int INF = 0x3f3f3f3f;
const LL LINF = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, -1, 1, -1, 1};
const int maxn = 1e2 + 10;
const int maxx = 1e12 + 10;
const double EPS = 1e-8;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int MOD = 1e3;
template <class T> inline T min(T a, T b, T c) {return min(min(a, b), c);}
template <class T> inline T max(T a, T b, T c) {return max(max(a, b), c);}
template <class T> inline T min(T a, T b, T c, T d) {return min(min(a, b), min(c, d));}
template <class T> inline T max(T a, T b, T c, T d) {return max(max(a, b), max(c, d));}
template <class T> inline bool scan_d(T &ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return 0;
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}
inline bool scan_lf(double &num) {
    char in;
    double Dec = 0.1;
    bool IsN = false, IsD = false;
    in = getchar();
    if (in == EOF) return false;
    while (in != '-' && in != '.' && (in < '0' || in > '9')) in=getchar();
    if (in == '-') {IsN = true; num = 0;}
    else if (in == '.') {IsD = true; num = 0;}
    else num = in - '0';
    if (!IsD) {
        while (in = getchar(), in >= '0' && in <= '9') {num *= 10; num += in - '0';}
    }
    if (in != '.') {
        if (IsN) num = -num;
        return true;
    }
    else{
        while (in = getchar(), in >= '0' && in <= '9') {
            num += Dec * (in - '0');
            Dec *= 0.1;
        }
    }
    if (IsN) num = num;
    return true;
}
void Out(LL a) {if(a < 0) {putchar('-'); a = -a;}if(a >= 10) Out(a / 10); putchar(a % 10 + '0');}
void print(LL a) {Out(a), puts("");}
/**********************************************WHITE_YASHA**********************************************/
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
//cerr << "run time is " << clock() << endl;
struct node {
    int x, y, id;
} nd[maxn];
int T, n, tot;
int p[maxn];
char type[maxn];
int cross(node p0, node p1, node p2) {
    return (p1.x - p0.x) * (p2.y - p0.y) - (p1.y - p0.y) * (p2.x - p0.x);
}
int dis(node p1, node p2) {
    return (p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y);
}
bool cmp(node p1, node p2) {
    int tmp = cross(nd[0], p1, p2);
    if (tmp > 0) return true;
    else if (!tmp && dis(nd[0], p1) < dis(nd[0], p2)) return true;
    else return false;
}
void graham() {
    int pos = 0;
    FOr (1, n, i) {
        if (nd[i].y < nd[pos].y || (nd[i].y == nd[pos].y && nd[pos].x > nd[i].x)) pos = i;
    }
    swap(nd[pos], nd[0]);
    sort(nd + 1, nd + n, cmp);
    FOR (0, 1, i) p[i] = i;
    tot = 2;
    FOr (2, n, i) {
        W (tot > 1 && cross(nd[p[tot - 2]], nd[p[tot - 1]], nd[i]) <= 0) tot--;
        p[tot++] = i;
    }
}
void init() {
    me(nd, 0);
    me(p, 0);
    me(type, 0);
    FOr (0, n, i) type[i] = 'B';
}
int main() {
    s_1(T);
    W (T--) {
        s_1(n);
        init();
        FOr (0, n, i) {
            s_2(nd[i].x, nd[i].y);
            nd[i].id = i;
        }
        graham();
        if (n < 3 || (n == 3 && tot == n)) {
            puts("NO");
            continue;
        }
        puts("YES");
        if (tot == n) type[nd[p[0]].id] = type[nd[p[2]].id] = 'A';
        else {
            FOr (0, tot, i) type[nd[p[i]].id] = 'A';
        }
        puts(type);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值