题目链接

题意:给出n个点。用两种颜色来给每个点染色。问能否存在一种染色方式,使不同颜色的点不能被划分到一条直线的两侧。

题解:求个凸包(其实只考虑四个点就行。但因为有板子,所以感觉这样写更休闲一些。)。如果不是所有点都在凸包上,那么把凸包上的点染成颜色1,内部的点染成颜色2;如果是所有点都在凸包上,且点数>3,那么将第一个和第三个点染成颜色1,其余点染成颜色2;否则,不存在满足要求的染色方式。

虽然很弱但是拿到一个一血还是非常开心的~

#include<bits/stdc++.h>
using namespace std;
typedef long long LL; const LL eps=1e-;
const LL pi=acos(-1.0); int dcmp(LL x)
{
if(x==0LL) return ;
else return x<? -:;
} 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_=,LL y_=)
{
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)==&&dcmp(y-rhs.y)==;
}
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)< && dcmp(c3)*dcmp(c4)<;
} bool OnSegment1(Point P,Point A,Point B)
{
return dcmp(Cross(P-A,P-B))== && dcmp(Dot(P-A,P-B))<=;
} 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=;
for(int i=; i<n; ++i)
{
while(m>&&dcmp(Area2(ch[m-],ch[m-],p[i]))<=) --m; //直到 ch[m-2],ch[m-1],p[i] 不是顺时针且不在同一直线
ch[m++]=p[i];
}
int k=m;
for (int i=n-; i>=; --i)
{
while(m>k&&dcmp(Area2(ch[m-],ch[m-],p[i]))<=) --m;
ch[m++]=p[i];
}
return n>?m-:m;
} //============================================== int n,nc;
Point p[],ch[];
int c[]; bool ok()
{
nc=ConvexHull(p,n,ch);
if(nc<n)
{
for(int i=;i<nc;i++)
c[ch[i].id]=;
return true;
}
else if(nc>)
{
c[ch[].id]=;
c[ch[].id]=;
return true;
}
else
return false;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
memset(c,,n*sizeof(int));
for(int i=;i<n;i++)
p[i].read(),p[i].id=i;
if(ok())
{
puts("YES");
for(int i=;i<n;i++)
printf("%c",c[i]?'A':'B');
puts("");
}
else
puts("NO");
}
}

hihocoder 1582 : Territorial Dispute (计算几何)(2017 北京网络赛E)的更多相关文章

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

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

  2. hihoCoder #1582 : Territorial Dispute 凸包

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

  3. hihocoder 1582 : Territorial Dispute(凸包)

    传送门 题意 略 分析 求一个凸包即可 1.所有点在凸包上且点数>3,令凸包上第1,3点为'A',其余点为'B' 2.部分点在凸包上,令凸包上点为'A',其余点为'B' 3.无可行情况 附代码 ...

  4. 2017北京网络赛 Bounce GCD加找规律

    题目链接:http://hihocoder.com/problemset/problem/1584 题意:就是求一个小球从矩阵的左上角,跑到矩形的右下角不能重复经过的格子,小球碰到墙壁就反射. 解法: ...

  5. hihoCoder #1388 : Periodic Signal ( 2016 acm 北京网络赛 F题)

    时间限制:5000ms 单点时限:5000ms 内存限制:256MB 描述 Profess X is an expert in signal processing. He has a device w ...

  6. hihocode 1584 : Bounce (找规律)(2017 北京网络赛G)

    题目链接 比赛时随便找了个规律,然后队友过了.不过那个规律具体细节还挺烦的.刚刚偶然看到Q巨在群里提到的他的一个思路,妙啊,很好理解,而且公式写起来也容易.OrzQ巨 #include<bits ...

  7. 2017北京网络赛 J Pangu and Stones 区间DP(石子归并)

    #1636 : Pangu and Stones 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In Chinese mythology, Pangu is the fi ...

  8. 2017北京网络赛 F Secret Poems 蛇形回路输出

    #1632 : Secret Poems 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 The Yongzheng Emperor (13 December 1678 – ...

  9. 2017 北京网络赛 E Cats and Fish

    Cats and Fish 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are many homeless cats in PKU campus. They ...

随机推荐

  1. symbol,iterator,generator

    1.symbol是在ES6中引入的一种基本数据类型,因为symbol是不重复.唯一的数据特性,symbol设计是被用来表示对象内部的私有属性的.     symbol.for与symbol.keyfo ...

  2. Monkey测试:日志信息分析

    在跑monkey时,我们需要将日志输出到文件,然后对日志信息进行分析. 一.输出日志到文件 在monkey命令后加>文件地址 如:adb shell monkey 1000>E:/text ...

  3. application.events 识别组合键 参考。

    https://blog.csdn.net/chinayu2007/article/details/43761277 在窗体上放上ApplicationEvents控件,在OnMessage消息中加入 ...

  4. Matlab——图形绘制——二维平面图形

    二维平面图形 hold on ————在已画好的图形上添加新的图形 plot 是绘制一维曲线的基本函数,但在使用此函数之前,我们需先定义曲线上每一点的x 及y 座标.下例可画出一条正弦曲线: > ...

  5. tensorflow学习之搭建最简单的神经网络

    这几天在B站看莫烦的视频,学习一波,给出视频地址:https://www.bilibili.com/video/av16001891/?p=22 先放出代码 #####搭建神经网络测试 def add ...

  6. ContextLoaderListener错误

    在web.xml中添加如下配置 <context-param> <param-name>contextConfigLocation</param-name> < ...

  7. 使用 Jenkins 打包成功后 运行 出现 Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

    linux 运行时 错误日志 Error starting ApplicationContext. To display the conditions report re-run your appli ...

  8. Dos - 学习总结(1)

    1.控制台复制 1>鼠标右键,标记. 2>选定复制内容后,鼠标右键,完成复制. 2.

  9. java通过正则进行语法分析实现表达式的逻辑判断和复杂计算实现

    首先功能展示: 相关功能实现,实现功能类似js,弱语言类型: 1.核销语法解析使用正则校验和匹配实现处理,每一行是一个完整表达式 2.有系统变量使用,内置的变量可直接获取值进行相关逻辑和条件计算 3. ...

  10. 【JZOJ 3909】Idiot 的乘幂

    题面: 正文: 把题目中的方程组组合在一起就变成了: \(X^{a+c}\equiv b \cdot d (\mod p)\) 那这时,我们假定两个数\(x\)和\(y\),使得: \(ax + cy ...