#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
平面内给出n个点,有两个人来占领这n个点,问有没有一种占领方式使得用一条直线不能分隔开两个人占领的点。如果有输出占领方式。
代码:
//少于3个点一定不能划分,3个点时如果三个点在一条直线上可以划分否则不能划分,大于三个点时求个凸包就行了,如果点全部在凸包
//上就每隔一个点属于同一个集合,否则图包内的点在一个集合,凸包上的在另一个集合
//这题用象限的极角排序好像不会对啊还是我写的有问题。。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int INF=0x7fffffff;
int top,n,q[],t;
bool vis[];
struct Node { double x,y;int id; }node[];
double dis(Node p1,Node p2)
{
return sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
}
double chaji(Node p0,Node p1,Node p2)
{
return ((p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x));
}
bool cmp(Node p1,Node p2)
{
double tmp=chaji(node[],p1,p2);
if(tmp>) return ;
else if(tmp<) return ;
else return dis(node[],p1)<dis(node[],p2);
}
void tubao()
{
q[]=;
q[]=;
top=;
for(int i=;i<n;i++){
while(top>&&chaji(node[q[top-]],node[q[top]],node[i])<=)
top--;
q[++top]=i;
}
}
int main()
{
scanf("%d",&t);
while(t--){
int min_i=;
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%lf%lf",&node[i].x,&node[i].y);
node[i].id=i;
if(node[min_i].y>node[i].y||(node[min_i].y==node[i].y&&node[min_i].x>node[i].x))
min_i=i;
}
if(n<=){
puts("NO");
continue;
}
swap(node[min_i],node[]);
sort(node+,node+n,cmp);
tubao();
if(n==&&top==){
puts("NO");
continue;
}
memset(vis,,sizeof(vis));
if(top==n-) vis[node[q[]].id]=vis[node[q[]].id]=;
else{
for(int i=;i<=top;i++) vis[node[q[i]].id]=;
}
puts("YES");
for(int i=;i<n;i++)
if(vis[i]) printf("A");
else printf("B");
printf("\n");
}
return ;
}
 

hihoCoder #1582 : Territorial Dispute 凸包的更多相关文章

  1. hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...

  2. hihocoder 1582 : Territorial Dispute(凸包)

    传送门 题意 略 分析 求一个凸包即可 1.所有点在凸包上且点数>3,令凸包上第1,3点为'A',其余点为'B' 2.部分点在凸包上,令凸包上点为'A',其余点为'B' 3.无可行情况 附代码 ...

  3. hihocoder 1582 : Territorial Dispute (计算几何)(2017 北京网络赛E)

    题目链接 题意:给出n个点.用两种颜色来给每个点染色.问能否存在一种染色方式,使不同颜色的点不能被划分到一条直线的两侧. 题解:求个凸包(其实只考虑四个点就行.但因为有板子,所以感觉这样写更休闲一些. ...

  4. 【分类讨论】【计算几何】【凸包】hihocoder 1582 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E. Territorial Dispute

    题意:平面上n个点,问你是否存在一种黑白染色方案,使得对于该方案,无法使用一条直线使得黑色点划分在直线一侧,白色点划分在另一侧.如果存在,输出一种方案. 如果n<=2,显然不存在. 如果所有点共 ...

  5. ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛

    编号 名称 通过率 通过人数 提交人数 A√水题(队友写的 Visiting Peking University 91% 1122 1228 B— Reverse Suffix Array 57% 6 ...

  6. words

    conscious[英][ˈkɒnʃəs][美][ˈkɑnʃəs]consensus[英][kənˈsensəs][美][kənˈsɛnsəs] scious sensuswaterflood; de ...

  7. [poj1113][Wall] (水平序+graham算法 求凸包)

    Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...

  8. hihocoder -1121-二分图的判定

    hihocoder -1121-二分图的判定 1121 : 二分图一•二分图判定 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 大家好,我是小Hi和小Ho的小伙伴Net ...

  9. Hihocoder 太阁最新面经算法竞赛18

    Hihocoder 太阁最新面经算法竞赛18 source: https://hihocoder.com/contest/hihointerview27/problems 题目1 : Big Plus ...

随机推荐

  1. js-jQuery对象与dom对象相互转换(转载)

    核心提示:jquery选择器得到的jquery对象和标准的 javascript中的document.getElementById()取得的dom对象是两种不同的对象类型,一般情况下,如S(’#id’ ...

  2. Amazon及其亏本诱饵策略还能坚持多久?

    Amazon 刚刚公布了最新的财报,亏损 4100 万美元.这是这家电子商务巨头连续 5 个季度以来的第 3 次亏损.但是华尔街似乎却一片叫好声,当日 Amazon 的股价也涨了近 8 个点达 359 ...

  3. Python基础知识-06-集合内存布尔False

    python其他知识目录 1.判断一个字符串中是否有敏感字符? #str: m_str="我叫魔降风云变" if "魔" in m_str: #判断指定字符是否 ...

  4. android点击事件的四种方式

    android点击事件的四种方式 第一种方式:创建内部类实现点击事件 代码如下: package com.example.dail; import android.text.TextUtils; im ...

  5. eclipse连接SQL2008R2

    最近又开始写JAVA WEB了,想起连接数据库就麻烦,但是通过一天的努力我居然弄好了,很有成就感. 我用的是 SQL Server 2008 R2  +  eclipse 首先要成功的安装好SQL最终 ...

  6. Android开发第二阶段(7)

    今天:对项目的最后总结,宣传给下届学生做准备.为了更好的了解和深入书写本次项目的总结随笔.

  7. 第四次c++作业

    一,GitHub地址 https://github.com/ronghuijun/3Elevators-scheduling 二,命令行和文件读写 百度有时候有点蒙,命令行用的是D:>Eleva ...

  8. UIView maskView属性

    给View1的maskView 赋值View2 1.View2不会显示在View1上: 2.View2 的alpha通道会体现在View1上. 关于maskView,Apple的解释: An opti ...

  9. URL相关Web APIs

    参考文档:MDN> Web API接口 > URLUtils MDN > Web API接口 > URL MDN > Web API接口 > Location MD ...

  10. QP(Quote-Printable) 编码

    QP(Quote-Printable)   方法,通常缩写为“Q”方法,其原理是把一个 8   bit   的字符用两个16进制数值表示,然后在前面加“=”.所以我们看到经过QP编码 后的文件通常是这 ...