题目链接

题意:给出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. 配置Log4j(很详细)【转】

    来自: http://www.blogjava.net/zJun/archive/2006/06/28/55511.html Log4J的配置文件(Configuration File)就是用来设置记 ...

  2. 阶段3 1.Mybatis_05.使用Mybatis完成CRUD_4 Mybatis的CRUD-查询一个和模糊查询

    模糊查询 测试的时候需要提供百分号的模糊查询.传入的参数提供百分号 所有包含王字的就都查询出来了.

  3. 【笔记】云主机当跳板,ssh tunnel远程登录树莓派

    问题 想要在外网登录家中局域网的树莓派,家里的网络外网ip的会变,而且不适合对公网暴露端口.调研了一番,发现可以使用云主机当跳板,结合ssh隧道实现远程登录到局域网中的树莓派 关于ssh隧道的原理可以 ...

  4. java一周学习记录(2017/12/2)

    姓名:Danny                               日期:2017/12/2 周日 周一 周二 周三 周四 周五 周六 所花时间 120 150 190 150 180 28 ...

  5. java 多线程并发问题总结

    java 多线程并发主要通过关键字synchronized实现 Java语言的关键字,当它用来修饰一个方法或者一个代码块的时候,能够保证在同一时刻最多只有一个线程执行该段代码. 一.当两个并发线程访问 ...

  6. iptables添加开放端口

    查看状态 iptables -L -n 编辑/etc/sysconfig/iptables -A INPUT -p tcp -m tcp --dport 4000 -j ACCEPT 重启 servi ...

  7. MySQL-快速入门(11)用户管理

    1.权限表 存储用户权限信息表主要有:user.db.host.tables_priv.columns_priv.procs_priv. 1>user表: 记录允许连接到服务器的账号信息,里面的 ...

  8. Tomcat 一台机器运行多个Tomcat

    转 https://www.cnblogs.com/andy1234/p/8866588.html 在一台Win10 PC 上面同时开启两个Tomcat系统为例. 1. 硬件环境 2. 到Tomcat ...

  9. Python win32com模块 合并文件夹内多个docx文件为一个docx

    Python win32com模块 合并文件夹内多个docx文件为一个docx #!/usr/bin/env python # -*- coding: utf-8 -*- from win32com. ...

  10. hdu1465不easy系列之中的一个(错排)

    版权声明:本文为博主原创文章,未经博主同意不得转载. vasttian https://blog.csdn.net/u012860063/article/details/37512659 转载请注明出 ...