#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. C++进阶训练——停车收费系统设计

    一.简介 经过一段时间的c++基础学习,是时候做一个较为全面的.运用c++功能的较复杂的项目练练手了. 运用软件:Visual Studio   (VS). 题目:c++停车收费系统设计(某本编程书进 ...

  2. springmvc 静态资源 配置

    SpringMVC提供<mvc:resources>来设置静态资源,但是增加该设置如果采用通配符的方式增加拦截器的话仍然会被拦截器拦截,可采用如下方案进行解决: 方案一.拦截器中增加针对静 ...

  3. win10 redis安装教程

    下载解压,没什么好说的,在解压后的目录下有以下这些文件: 在 命令行 启动服务端 redis目录下执行: redis-server.exe redis.windows.conf 如果需要 开机启动:执 ...

  4. Centos上搭建git服务

    1.安装Git $ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel $ yum ...

  5. 20181120-10 Beta阶段第2周/共2周 Scrum立会报告+燃尽图 7

    此作业要求参见:[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2415] 版本控制地址    [https://git.coding.n ...

  6. 20135313_exp5

    课程:Java程序与设计     班级:1353 姓 名:吴子怡  学号:20135313 小组成员: 20135113肖昱 成绩:             指导教师:娄嘉鹏       实验日期:2 ...

  7. 每日Scrum--No.3

    Yesterday:帮着队友一起打开地图 Today:学习迪杰斯特拉算法,试着编写程序代码 Problem:语法逻辑出错,在执行的时候,有的时候出现死循环,有的时候屏幕出现null和乱码.语句的编写有 ...

  8. Alpha 冲刺(9/10)

    队名 火箭少男100 组长博客 林燊大哥 作业博客 Alpha 冲鸭鸭鸭鸭鸭鸭鸭鸭鸭! 成员冲刺阶段情况 林燊(组长) 过去两天完成了哪些任务 协调各成员之间的工作 多次测试软件运行 学习OPENMP ...

  9. .net学习-扩展

    uwp uwpapp-斗鱼,微信等 云和移动优先 远程桌面连接设置 teamviewer V8内核 Node.js javascript 事件循环 express框架 bootstrap NoSQL ...

  10. 0302思考IT行业的感想

    在看完这两篇报道IT行业的报道后,可以看出IT行业在整个就业行业中是一个十分热门的行业,而且薪酬也相对较高,企业对于各种IT人才的需求很大,意味着就业的面较宽且就业的前景比较乐观.但是随之而来的问题是 ...