题目链接

题意:给出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. 【汇总】Wireshark 过滤规则

    作者:Bay0net 时间:2019-07-01 14:20:09 更新: 介绍:记录使用过的 wireshark 过滤规则 0x01. 使用介绍 抓包采用 wireshark,提取特征时,要对 se ...

  2. CentOS6.5 编译安装PHP5.6(apache模块)

    一.环境准备 1. 下载php源码包 # wget http://cn2.php.net/distributions/php-5.6.30.tar.gz # tar -xf php-5.6.30.ta ...

  3. 004-Django 关于 templates的部分操作

    Django 模版 {% %} 为django模版语言标签,用于加载文件 {{ }} 为django模版语言标签,用于定义显示变量 for循环 {% for user in users %} < ...

  4. 【FICO系列】SAP FICO FS00修改科目为未清项目管理

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[FICO系列]SAP FICO FS00修改科 ...

  5. .net core 学习小结之 Cookie-based认证

    在startup中添加授权相关的管道 using System; using System.Collections.Generic; using System.Linq; using System.T ...

  6. C# 编写的webservice 怎样返回XML数据

    [WebMethod] public string GetXml() { string sConStr = ConfigurationManager.ConnectionStrings["c ...

  7. 第四周课程总结与第二次实验报告(Java简单类与对象)

    1.写一个名为Rectangle的类表示矩形.其属性包括宽width.高height和颜色color,width和height都是double型的,而color则是String类型的.要求该类具有: ...

  8. 使用certbot 为nginx或openresty启用https

    certbot 使用letsencrypt 生成免费https证书 以下内容网上整理,原文地址 https://segmentfault.com/a/1190000005797776 -------- ...

  9. CVE 2019 0708 安装重启之后 可能造成 手动IP地址丢失.

    1. 最近两天发现 更新了微软的CVE 2019-0708的补丁之后 之前设置的手动ip地址会变成 自动获取, 造成ip地址丢失.. 我昨天遇到两个, 今天同事又遇到一个.微软做补丁也不走心啊..

  10. ubuntu或linux下找不到apache服务器配置文件httpd.conf

    原因是ubuntu中是apache2,没有httpd.conf文件,所有找不到. 我的是ubuntu14.04系统,apache2配置文件在/etc/apache2/apache2.conf中, 如果 ...