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 ...
随机推荐
- JAVA学习笔记--匿名内部类
匿名内部类,即没有名字的内部类. 我们在编写JAVA程序时,往往要创建很多类,类是可以被重复使用的.但有时,我们创建了一个类,却只需要使用该类一次,那么单独为其编写一个类就显得有些麻烦,这时可以使用匿 ...
- java引用Arcface,实现人脸识别(demo)
## 开发环境准备: ###开发使用到的软件和工具: * Jdk8.mysql5.7.libarcsoft_face.dll(so).libarcsoft_face_engine.dll(so).li ...
- 学习使用Git 版本控制 代码管理
title: 学习使用Git 版本控制 代码管理 notebook: 经验累积 tags:Git --- Git 版本控制 学习教程 Git版本控制器,可以作为程序员.计算机科学和软件工程的研究人员在 ...
- linux 性能分析命令及其解释
很多时候,我们需要对linux上运行的环境大体有一个了解,那么久需要大体知道当前系统的相关资源的使用情况,那么可以用一些linux提供的丰富的命令来查看 性能分析 vmstat 虚拟内存统计 用法 U ...
- java不用任何已有方法完全自写的去重法
package aa; class InsertSort{ private long[] a; private int nElems; //构造方法 public InsertSort(int max ...
- 过山车 HDU 2063 (二分图匹配裸题)
Problem Description RPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了.可是,过山车的每一排只有两个座位,而且还有条不成文的规矩,就是每个女生必须找个个男生 ...
- Scrum立会报告+燃尽图(十月十三日总第四次):前期宣传相关工作
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2194 Scrum立会master:刘欣 一.小组介绍 组长:付佳 组员: ...
- 1.2Linux下C语言开发基础(学习过程)
===============第二节 Linux下C语言开发基础=========== ********************** 重要知识点总结梳理********************* 一 ...
- 敏捷开发 Scrum 综述
敏捷开发 Scrum 综述 这一星期学习了敏捷开发,然后阅读了相关的书籍,从网上查找了很多相关的资料,对敏捷开发scrum有了更加深刻了理解,对敏捷开发做了如下总结: 一.什么是敏捷开发? 敏捷开发提 ...
- 软工1816 · 第八次作业(课堂实战)- 项目UML设计(团队)
本次作业博客 团队信息 队名:起床一起肝活队 原组长: 白晨曦(101) 原组员: 李麒 (123) 陈德斌(104) 何裕捷(214) 黄培鑫(217) 王焕仁(233) 林志华(128) 乐忠豪( ...