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 ...
随机推荐
- wiki平台工具
1. confluence 评点: 好用,与world类似.模板多.
- Spring Boot 使用Java代码创建Bean并注冊到Spring中
从 Spring3.0 開始,添加了一种新的途经来配置Bean Definition,这就是通过 Java Code 配置 Bean Definition. 与Xml和Annotation两种配置方式 ...
- poj 3169 Layout(差分约束)
Layout Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6549 Accepted: 3168 Descriptio ...
- 如何在List集合中去重
众所周知List集合中的元素是有序的,但是List中的元素同样是可以重复的,那么我们应该怎么在List集合中去重呢? 方法一: 对于方法一而言,这也许是一个小窍门.利用的是Set集合中不允许出现重复的 ...
- Intel MIC
http://en.wikipedia.org/wiki/Intel_MIC Intel MIC From Wikipedia, the free encyclopedia Intel Man ...
- 赵雅智_SimpleCursorAdapter
项目步骤 声明listView控件并获取显示的视图 获取显示的数据 设置显示的adapter 注冊点击事件 详细案例 实现效果: watermark/2/text/aHR0cDovL2Jsb2cuY3 ...
- Finally语句块的运行
一.finally语句块是否一定运行? Java中异常捕获机制try...catch...finally块中的finally语句是不是一定会被运行?非常多人都说不是.当然他们的回答是正确的,经过试验. ...
- UIPanGestureRecognizer上下左右滑动方向推断算法
CGFloat const gestureMinimumTranslation = 20.0; typedef enum :NSInteger { kCameraMoveDirectionNone, ...
- bash exec
1 当exec执行命令时,会为该命令创建shell进程,并且终止老的shell进程的执行,并且保留老的shell进程的进程号 [root@localhost ~]# cat test_exec.sh ...
- inherited在消息中的作用(编译器根据inherited所在的函数,直接转换成对祖先类同名动态函数的调用,或者转换成对DefaultHandler的调用)
好奇一下.看来Object Pascal确实与Windows深入结合了. unit Unit1; interface uses Windows, Messages, SysUtils, Variant ...