题目链接

题意:给出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. c# AES128 加解密算法

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  2. Java多线程学习——死锁的一个容易理解的例子

    发生死锁的情况:多个线程需要同时占用多个共享资源而发生需要互相死循环等待的情况 public class Mirror { //镜子 } public class Lipstick { //口红 } ...

  3. junper防火墙之自摆乌龙

    Juniper防火墙划分三个端口: 1.E0/0连接内网网络,网段是172.16.1.0/24,E0/0的端口ip地址是172.16.1.1,作为内网网络的网关 2.E0/1连接DMZ区域,网段是17 ...

  4. django 的 一对多的关系

    USERINFO 用户详情表 USERTYPE 用户类别表 UserType是父表,UserInfo是子表, user_type 是 关联字段 就是新增资源的时候,又对数据库重新查询一遍,太消耗资源了 ...

  5. [转帖]IIS7.5应用程序池集成模式和经典模式的区别介绍

    IIS7.5应用程序池集成模式和经典模式的区别介绍 之前转帖过一个 但是感觉不如这个说的细: https://www.jb51.net/article/31010.htm 关注脚本之家微信公众号(jb ...

  6. shell script简单笔记

    变量 shell script是一种脚本语言,变量的定义是通过 myName=HYB 这样的形式定义的. 当存在空格时,可以通过双引号或单引号将其变为字符串.双引号不进行转义,单引号将内容进行转义为一 ...

  7. linux的进程间通信概述

    一 进程间通信 1.1. linux内核提供多种进程间通信机制 a. 无名管道和有名管道 b. SystemV IPC:信号量.消息队列.共享内存 c. Socket域套接字 d. 信号 1.2. 无 ...

  8. 洛谷 P5660 数字游戏 & [NOIP2019普及组]

    传送门 洛谷改域名了QAQ 解题思路 没什么好说的,一道红题,本不想发这篇博客 ,但还是尊重一下CCF吧QAQ,怎么说也是第一年CSP呢! 用getchar一个个读入.判断.累加,最后输出即可. 不过 ...

  9. Chrome开发者工具详解(二)之使用断点调试代码下

    JS调试技巧 技巧一:格式化压缩代码 技巧二:快速跳转到某个断点的位置 右侧的Breakpoints会汇总你在JS文件所有打过的断点,点击跟checkbox同一行的会暂时取消这个断点,若是点击chec ...

  10. html常用标签、包含关系、常用术语,以及网页设计中的字体分类

    编程比较舒适的等宽字体:DejaVu Sans Mono 字体的分类: serif (衬线字体){在笔画上面有些特殊的修饰效果} sans-serif (非衬线字体){横平竖直.横就是横,点就是点} ...