传送门

题意

分析

求一个凸包即可

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(凸包)的更多相关文章

  1. hihoCoder #1582 : Territorial Dispute 凸包

    #1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...

  2. hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...

  3. hihocoder 1582 : Territorial Dispute (计算几何)(2017 北京网络赛E)

    题目链接 题意:给出n个点.用两种颜色来给每个点染色.问能否存在一种染色方式,使不同颜色的点不能被划分到一条直线的两侧. 题解:求个凸包(其实只考虑四个点就行.但因为有板子,所以感觉这样写更休闲一些. ...

  4. 【分类讨论】【计算几何】【凸包】hihocoder 1582 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E. Territorial Dispute

    题意:平面上n个点,问你是否存在一种黑白染色方案,使得对于该方案,无法使用一条直线使得黑色点划分在直线一侧,白色点划分在另一侧.如果存在,输出一种方案. 如果n<=2,显然不存在. 如果所有点共 ...

  5. ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛

    编号 名称 通过率 通过人数 提交人数 A√水题(队友写的 Visiting Peking University 91% 1122 1228 B— Reverse Suffix Array 57% 6 ...

  6. words

    conscious[英][ˈkɒnʃəs][美][ˈkɑnʃəs]consensus[英][kənˈsensəs][美][kənˈsɛnsəs] scious sensuswaterflood; de ...

  7. [poj1113][Wall] (水平序+graham算法 求凸包)

    Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...

  8. hihocoder -1121-二分图的判定

    hihocoder -1121-二分图的判定 1121 : 二分图一•二分图判定 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 大家好,我是小Hi和小Ho的小伙伴Net ...

  9. Hihocoder 太阁最新面经算法竞赛18

    Hihocoder 太阁最新面经算法竞赛18 source: https://hihocoder.com/contest/hihointerview27/problems 题目1 : Big Plus ...

随机推荐

  1. kibana dev tools快捷键

    kibana dev tools快捷键 ctrl+enter  提交请求 ctrl+i 自动缩进 ctrl+enter 提交请求 down 打开自动补全菜单 enter或tab 选中项自动补全 esc ...

  2. 转: 工欲善其事,必先利其器系列--Netbeans之远程开发

    转自: http://www.cnblogs.com/zuoca/archive/2012/07/09/Remote_Development_With_Netbeans_origin.html 工欲善 ...

  3. Thinking in React(翻译)

    下面是React官方文档中的Thinking inReact文章的翻译,第一次翻译英文的文章,肯定有非常多不对的地方,还望多多包涵. 原文地址:https://facebook.github.io/r ...

  4. 小程序 - Template

    关于模板,参见:https://mp.weixin.qq.com/debug/wxadoc/dev/framework/view/wxml/template.html 引入模块 <import ...

  5. 【整理】nand相关

    记录nand相关知识.主要是mtd和ubi 什么是UBI 它是一种flash管理方式 flash是一系列连续的物理擦除块组成的. UBI卷是一系列连续的逻辑擦除块(eraseblock),每一块都能够 ...

  6. C++中结构和类的区别

    首先从从语言角度来看,c语言是一种结构化的语言,便于按照模块化的方式来组织程序,易于程序员的调试和维护,而对于c++来说,我么可以认为它是标准c的超集.实际上所有的c程序也是c++程序.但两者之间还是 ...

  7. springmvc学习笔记(18)-json数据交互

    springmvc学习笔记(18)-json数据交互 标签: springmvc springmvc学习笔记18-json数据交互 springmvc进行json交互 环境准备 加入json转换的依赖 ...

  8. hadoop rsync

    1 rsync用来同步配置文件 rsync用来同步两个文件夹,它拷贝的是二者的差异,因此速度很快.在hadoop脚本中,rsync用来同步配置文件. 2 HADOOP_SLAVE_SLEEP的用途 大 ...

  9. TButton.Repaint的执行过程

    测试,在按钮事件里写上 Button1.Repaint;(包括TWinControl.Invalidate;和procedure TWinControl.Update;两个函数,会被TButton所继 ...

  10. BAPI_PO_CEATE 与PO_1