hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#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
题目链接:
http://hihocoder.com/problemset/problem/1582
题目大意:
一个二维平面,上面有一些点,问是否存在01染色方案,使得0和1的点无法被一条直线区分开。
题目思路:
【凸包】
一开始题目看错了以为是沿着网格的边的折线。。
首先可以知道n>3时只要满足存在两条线段,一条以2个0为端点,一条以2个1为端点,这两条线段相交即可
n=3时三角形无解,共线时中间的点为0,端点为1即可。
n=2或者1时无解。
可以求个凸包,然后判断,如果有节点不在凸包上,那么必有解,将不在凸包的点染为1,在的为0,即可。
如果节点全在凸包上,若n>3,则取不相邻的两个节点染为1,其余为0即可。否则无解。
/**************************************************** Author : Coolxxx
Copyright 2017 by Coolxxx. All rights reserved.
BLOG : http://blog.csdn.net/u010568270 ****************************************************/
#include<bits/stdc++.h>
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define mem(a,b) memset(a,b,sizeof(a))
const double EPS=0.00001;
const int J=;
const int MOD=;
const int MAX=0x7f7f7f7f;
const double PI=3.14159265358979323;
const int N=;
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans;
bool mark[N];
class xxx
{
public:
int x,y,num;
xxx(){}
xxx(int x,int y)
{
this->x=x;
this->y=y;
}
int dis()
{
return sqr(x)+sqr(y);
}
int dis(xxx aa)
{
return sqr(x-aa.x)+sqr(y-aa.y);
}
xxx operator - (const xxx &bb)
{
return xxx(this->x-bb.x,this->y-bb.y);
}
}a[N],s[N];
int Cross(xxx aa,xxx bb)
{
return aa.x*bb.y-aa.y*bb.x;
}
int Cross(xxx aa,xxx bb,xxx cc)
{
return Cross(bb-aa,cc-aa);
}
bool cmp1(xxx aa,xxx bb)
{
return aa.y!=bb.y?aa.y<bb.y:aa.x<bb.x;
}
bool cmp(xxx aa,xxx bb)
{
return Cross(a[],aa,bb)!=?(Cross(a[],aa,bb)>):(aa.dis(a[])<bb.dis(a[]));
}
bool judge()
{
int i;
if(lll<n)
{
for(i=;i<=lll;i++)
mark[s[i].num]=;
return ;
}
else if(n>)
{
mark[s[].num]=mark[s[].num]=;
return ;
}
else return ;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,z;
for(scanf("%d",&cass);cass;cass--)
// init();
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%d",&n))
{
mem(mark,);lll=;
scanf("%d",&n);
for(i=;i<=n;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
a[i].num=i;
}
sort(a+,a++n,cmp1);
sort(a+,a++n,cmp);
for(i=;i<=n;i++)
{
while(lll> && Cross(s[lll-],a[i],s[lll])>=)
lll--;
s[++lll]=a[i];
} for(i=;i<=lll;i++)s[i+lll]=s[i];
for(i=,j=;i<=lll;i++)
if(s[i].num<s[j].num)j=i;
for(i=j;i<j+lll;i++)
printf("%d ",s[i].num);
puts(""); if(judge())
{
puts("YES");
for(i=;i<=n;i++)
printf("%c",mark[i]?'A':'B');
puts("");
}
else puts("NO");
}
return ;
}
/*
// //
*/
hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)的更多相关文章
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛
编号 名称 通过率 通过人数 提交人数 A√水题(队友写的 Visiting Peking University 91% 1122 1228 B— Reverse Suffix Array 57% 6 ...
- 【分类讨论】【计算几何】【凸包】hihocoder 1582 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E. Territorial Dispute
题意:平面上n个点,问你是否存在一种黑白染色方案,使得对于该方案,无法使用一条直线使得黑色点划分在直线一侧,白色点划分在另一侧.如果存在,输出一种方案. 如果n<=2,显然不存在. 如果所有点共 ...
- hihoCoder 1584 Bounce 【数学规律】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1584 : Bounce 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 For Argo, it is very interesting watching a cir ...
- hihoCoder 1578 Visiting Peking University 【贪心】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1578 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for ...
- hihoCoder 1586 Minimum 【线段树】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1586 : Minimum 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2 ...
- hihocoder 1586 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-题目9 : Minimum【线段树】
https://hihocoder.com/problemset/problem/1586 线段树操作,原来题并不难..... 当时忽略了一个重要问题,就是ax*ay要最小时,x.y可以相等,那就简单 ...
- 【线段树】hihocoder 1586 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 I. Minimum
题意:给你一个序列(长度不超过2^17),支持两种操作:单点修改:询问区间中最小的ai*aj是多少(i可以等于j). 只需要线段树维护区间最小值和最大值,如果最小值大于等于0,那答案就是minv*mi ...
- 【最短路】【Heap-dijkstra】hihocoder 1587 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 J. Typist's Problem
题意:给你一个串,仅含有a~g,且每个字母只出现最多一次.和一个光标初始位置,以及一个目标串,问你最少要多少的代价变化成目标串. 有五种操作:在光标前添加一个未出现过的字母,代价1. 删除光标前或者光 ...
- hihoCoder #1586 : Minimum-结构体版线段树(单点更新+区间最值求区间两数最小乘积) (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1586 : Minimum Time Limit:1000ms Case Time Limit:1000ms Memory Limit:256MB Description You are give ...
随机推荐
- [BZOJ1419] Red is good(期望DP)
传送门 逆推 只不过顺序还是顺着的,思想是逆着的 f[i][j]表示还剩下i张红牌,j张黑牌的期望值 那么边界是 f[i][0]=i,因为只剩i张红牌 f[0][j]=0,只剩黑牌,显然直接停止最优 ...
- 【Codeforces Round #504 (Div. 1 + Div. 2) 】
A:https://www.cnblogs.com/myx12345/p/9843678.html B:https://www.cnblogs.com/myx12345/p/9843709.html ...
- 跳蚤 BZOJ 4310
跳蚤 [问题描述] 很久很久以前,森林里住着一群跳蚤.一天,跳蚤国王得到了一个神秘的字符串,它想进行研究. 首先,他会把串分成不超过 k 个子串,然后对于每个子串 S,他会从S的所有子串中选择字典序最 ...
- 标准C程序设计七---05
Linux应用 编程深入 语言编程 标准C程序设计七---经典C11程序设计 以下内容为阅读: <标准C程序设计>(第7版) 作者 ...
- elasticsearch入门使用(一)es 6.2.2安装,centos 7
elasticsearch(一般叫es)是基于Lucene的搜索服务器,提供http协议接口使用json格式数据,也提供相应的客户端,更详细的信息[优点&场景]请百度百科, 以下官网截图,官网 ...
- (43)C#网络1 http
一.HttpClient类 用于发送http请求,并接受请求的相应 (从4.5起开始可用) using System.Net.Http; 异步调用 HttpClient httpClient = ne ...
- Struts2 文件上传和下载
首先我们写一个单文件长传的fileupload.jsp: <body> <s:fielderror></s:fielderror> <!-- 报错信息 --& ...
- AIO
IBM® 市场 (英文) 提交 我的 IBM 站点导航 学习 开发 社区 学习 Java technology 内容 概览 简单介绍 Asynchronous I/O 开始简单的异步 I/ ...
- codechef Chef and Problems
终于补出这道:一直耽搁到现在 找到一个代码可读性很好的分块temp; 题意:给一个长度为n 的数组 A,Q次询问,区间相等数的最大范围是多少? 数据范围都是10e5; 当然知道分块了: 传统分块看各种 ...
- IO流的文件复制
1.IO流的分类 1.根据处理数据类型的不同分为: 字符流:1)Reader 读取字符流的抽象类 常用方法: read() 读取单个字符 read(char[] cbuf) 将字符读入数组. read ...