hihocoder 1582 : Territorial Dispute(凸包)
传送门
题意
略
分析
求一个凸包即可
1.所有点在凸包上且点数>3,令凸包上第1,3点为'A',其余点为'B'
2.部分点在凸包上,令凸包上点为'A',其余点为'B'
3.无可行情况
附代码
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL eps=1e-10;
const LL pi=acos(-1.0);
int dcmp(LL x)
{
if(x==0LL) return 0;
else return x<0? -1:1;
}
struct Point
{
LL x,y;
int id;
void read()
{
scanf("%lld%lld",&x,&y);
}
void output()
{
printf("%lld %lld\n",x,y);
}
Point(LL x_=0,LL y_=0)
{
x=x_,y=y_;
}
Point operator -(const Point& rhs)
{
return Point(x-rhs.x,y-rhs.y);
}
Point operator +(const Point& rhs)
{
return Point(x+rhs.x,y+rhs.y);
}
Point operator *(const LL& t)
{
return Point(x*t,y*t);
}
Point operator /(const LL& t)
{
return Point(x/t,y/t);
}
bool operator ==(const Point& rhs)
{
return dcmp(x-rhs.x)==0&&dcmp(y-rhs.y)==0;
}
bool operator<(const Point& rhs)const
{
return x<rhs.x||x==rhs.x&&y<rhs.y;
}
};
typedef Point Vector;
LL Cross(Vector A,Vector B)
{
return A.x*B.y-A.y*B.x;
}
LL Dot(Vector A,Vector B)
{
return A.x*B.x+A.y*B.y;
}
LL Area2(Point A,Point B,Point C)
{
return Cross(B-A,C-A);
}
bool SegmentProperIntersection(Point A1,Point B1,Point A2,Point B2)
{
LL c1=Cross(B1-A1,A2-A1),c2=Cross(B1-A1,B2-A1),
c3=Cross(B2-A2,A1-A2),c4=Cross(B2-A2,B1-A2);
return dcmp(c1)*dcmp(c2)<0 && dcmp(c3)*dcmp(c4)<0;
}
bool OnSegment1(Point P,Point A,Point B)
{
return dcmp(Cross(P-A,P-B))==0 && dcmp(Dot(P-A,P-B))<=0;
}
bool SegmentIntersection(Point A1,Point B1,Point A2,Point B2)
{
return SegmentProperIntersection(A1,B1,A2,B2) ||
OnSegment1(A2,A1,B1)||OnSegment1(B2,A1,B1) ||
OnSegment1(A1,A2,B2)||OnSegment1(B1,A2,B2);
}
int ConvexHull(Point *p,int n,Point *ch)
{
sort(p,p+n);
int m=0;
for(int i=0; i<n; ++i)
{
while(m>1&&dcmp(Area2(ch[m-2],ch[m-1],p[i]))<=0) --m; //直到 ch[m-2],ch[m-1],p[i] 不是顺时针且不在同一直线
ch[m++]=p[i];
}
int k=m;
for (int i=n-2; i>=0; --i)
{
while(m>k&&dcmp(Area2(ch[m-2],ch[m-1],p[i]))<=0) --m;
ch[m++]=p[i];
}
return n>1?m-1:m;
}
//==============================================
int n,nc;
Point p[105],ch[105];
int c[105];
bool judge()
{
int cnt=ConvexHull(p,n,ch);//计算在凸包上的点
if(cnt<n)
{
for(int i=0;i<cnt;++i) c[ch[i].id]=1;
return 1;
}
else if(cnt>3)
{
c[ch[0].id]=c[ch[2].id]=1;
return 1;
}
else return 0;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
memset(c,0,n*sizeof(int));
for(int i=0;i<n;i++)
p[i].read(),p[i].id=i;
if(judge())
{
puts("YES");
for(int i=0;i<n;++i) if(c[i]) putchar('A');else putchar('B');
puts("");
}
else
puts("NO");
}
return 0;
}
hihocoder 1582 : Territorial Dispute(凸包)的更多相关文章
- hihoCoder #1582 : Territorial Dispute 凸包
#1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...
- 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 (计算几何)(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 ...
随机推荐
- centos 7 卸載 mysql
跟網上文章,安裝了一個mysqlwget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 記下卸載過程: 首先执行查看命令 ...
- 用df命令显示磁盘使用量和占用率。
使用“df -k”命令,以k为单位显示磁盘使用量和占用率. root@gsg43:/tmp# df -kFilesystem 1K-blocks Used Available Use% ...
- Android4.42-Setting源代码分析之蓝牙模块Bluetooth(下)
接着上一篇Android4.42-Settings源代码分析之蓝牙模块Bluetooth(上) 继续蓝牙模块源代码的研究 THREE.蓝牙模块功能实现 switch的分析以及本机蓝牙重命名和可见性的分 ...
- c程序设计语言第一章2
练习1.13编写一个程序,打印输入中单词长度的直方图.水平方向的直方图比较容易绘制,垂直方向的直方图则要困难些 #include <stdio.h> #include <stdlib ...
- LeetCode_DP_Word Break II
LeetCode_Word Break II 一.题目描写叙述: 二.解决思路: 题目要求我们要在原字符串中加空格,使得隔开的每一个词都是词典中的词. 所以我们大能够按顺序扫描每一个字符.可是然后当碰 ...
- Enum to String 一般用法
目录 一.Enum Review 二.使用name()方法转换为String 三.使用toString()方法转换为String 四.使用成员属性转换为String 一.Enum Review J ...
- android studio 非法字符: '\ufeff' 解决方式
今天发现一个问题,就是从其它地方拷贝的代码到AS项目里面,木有语法 错误,可是就是执行不起来,老是报错"非法字符: '\ufeff' ",郁闷非常久.木有看到这个字符.最后查询了这 ...
- redis中键值对中值的各种类型
1 value的最基本的数据类型是String 2 如果value是一张图片 先对图片进行base64编码成一个字符串,然后再保存到redis中,用的时候进行base64解码即可. 这是base64的 ...
- 在安卓6.0(及以上)设备上无法获取无线网卡MAC地址的解决方案
在安卓6.0以下的设备上,通过WifiManager.getConnectionInfo().getMacAddress()即可获取WLAN物理地址, 而在6.0及以上,以此方式获取到的MAC地址为固 ...
- 教你如何配置Ubuntu用于高效、高质量的发送邮件
本文首发在: http://mengxi.me/how-to-setup-ubuntu-sendmail-to-deliver-email-fast-and-reliable/ 在网站上线后,经常会遇 ...