hihoCoder #1582 : Territorial Dispute 凸包
-
#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 凸包的更多相关文章
- hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...
- hihocoder 1582 : Territorial Dispute(凸包)
传送门 题意 略 分析 求一个凸包即可 1.所有点在凸包上且点数>3,令凸包上第1,3点为'A',其余点为'B' 2.部分点在凸包上,令凸包上点为'A',其余点为'B' 3.无可行情况 附代码 ...
- hihocoder 1582 : Territorial Dispute (计算几何)(2017 北京网络赛E)
题目链接 题意:给出n个点.用两种颜色来给每个点染色.问能否存在一种染色方式,使不同颜色的点不能被划分到一条直线的两侧. 题解:求个凸包(其实只考虑四个点就行.但因为有板子,所以感觉这样写更休闲一些. ...
- 【分类讨论】【计算几何】【凸包】hihocoder 1582 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E. Territorial Dispute
题意:平面上n个点,问你是否存在一种黑白染色方案,使得对于该方案,无法使用一条直线使得黑色点划分在直线一侧,白色点划分在另一侧.如果存在,输出一种方案. 如果n<=2,显然不存在. 如果所有点共 ...
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛
编号 名称 通过率 通过人数 提交人数 A√水题(队友写的 Visiting Peking University 91% 1122 1228 B— Reverse Suffix Array 57% 6 ...
- words
conscious[英][ˈkɒnʃəs][美][ˈkɑnʃəs]consensus[英][kənˈsensəs][美][kənˈsɛnsəs] scious sensuswaterflood; de ...
- [poj1113][Wall] (水平序+graham算法 求凸包)
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...
- hihocoder -1121-二分图的判定
hihocoder -1121-二分图的判定 1121 : 二分图一•二分图判定 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 大家好,我是小Hi和小Ho的小伙伴Net ...
- Hihocoder 太阁最新面经算法竞赛18
Hihocoder 太阁最新面经算法竞赛18 source: https://hihocoder.com/contest/hihointerview27/problems 题目1 : Big Plus ...
随机推荐
- 如何让QT程序以管理员权限运行(UAC)
方案一:(仅适用于使用msvc编译器) 在PRO文件中添加一行指令即可, QMAKE_LFLAGS += /MANIFESTUAC:"level='requireAdministrator' ...
- VisualSVN Server的迁移
VisualSVN Server迁移涉及到两种情况: 第一种情况:VisualSVN Server没有更换电脑或者服务器,只是修改Server name. 第二种情况:当VisualSVN Serve ...
- 3.hive的thriftserver服务
1.ThiftServer介绍 正常的hive仅允许使用HiveQL执行查询.更新等操作,并且该方式比较笨拙单一.幸好Hive提供了轻客户端的实现,通过HiveServer或者HiveServer2, ...
- RIGHT-BICEP测试第二次程序
根据Right-BICEP单元测试的方法我对我写的第二次程序进行了测试: 测试一:测试能否控制使用乘除 测试二:测试是否能加括号 测试三:是否可以控制题目输出数量 测试四:能否控制输出方式,选择文件输 ...
- SpringMVC相关的面试题
1.什么是springMVC springmvc是spirng框架的一个模块,是一个基于MVC框架的web框架 2.springmvc的流程 a.客户端发送请求 b.前端控制器DispatcherSe ...
- 软工1816 · Alpha冲刺(5/10)
团队信息 队名:爸爸饿了 组长博客:here 作业博客:here 组员情况 组员1(组长):王彬 过去两天完成了哪些任务 后端代码复审 福大各个食堂的菜品口味量化.属性标记 组织前后端线下协作 接下来 ...
- 福大软工1816:Beta(1/7)
Beta 冲刺 (1/7) 队名:第三视角 组长博客链接 本次作业链接 团队部分 团队燃尽图 工作情况汇报 张扬(组长) 过去两天完成了哪些任务 文字/口头描述 答辩 组织会议 复习课本 展示GitH ...
- s2sh乱码一个小处理(新手按流程走)
解决乱码几小点: 1.配置过滤器,可以选择自己写,既然你用的SSH框架就更简单了,直接用Spring的过滤器,web.xml里配置一下即可. 2.Jsp页面设置编码,所有地方都要相同,我习惯用GBK ...
- C++ Primer Plus学习:第十四章
第十四章 C++中的代码重用 包含对象成员的类 将类的对象作为新类的成员.称为has-a关系.使用公有继承的时候,类可以继承接口,可能还有实现(纯虚函数不提供实现,只提供接口).使用包含时,可以获得实 ...
- Qt多线程-QThread
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt多线程-QThread 本文地址:http://techieliang.com/2 ...