题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6590

题目大意(来自队友):二维平面上有\(n\)个点,每个点要么是黑色要么是白色,问能否找到一条直线将平面分割成黑白两部分

题解:分别对每种颜色的点求凸包,判断是否相交即可。

(有模板真好)

 #include<bits/stdc++.h>
//#include<cstdio>
//#include<cmath>
//#include<algorithm>
using namespace std;
typedef long double lod;
typedef long long ll;
typedef long double ld;
const ld eps=1e-;
const ld pi=acos(-1.0);
int sgn(ld x)
{
if (x<-eps) return -;
if (x>eps) return ;
return ;
} struct P;
struct LINE;
struct CIRCLE;
struct TRIANGLE;
struct POLYGON; void kr(ld &x)
{
double t; scanf("%lf",&t);
x=t;
}
void kr(ll &x)
{
scanf("%lld",&x);
}
struct P
{
lod x,y;
void read()
{
kr(x); kr(y);
}
P operator+(const P &t)const
{
return {x+t.x,y+t.y};
}
P operator-(const P &t)const
{
return {x-t.x,y-t.y};
}
P operator*(ld t)const
{
return {x*t,y*t};
}
P operator/(ld t)const
{
return {x/t,y/t};
}
lod operator*(const P &t)const
{
return x*t.y-y*t.x;
}
lod operator%(const P &t)const
{
return x*t.x+y*t.y;
}
bool operator<(const P &t)const
{
return sgn(x-t.x)<||sgn(x-t.x)==&&sgn(y-t.y)<;
}
bool operator==(const P &t)const
{
return sgn(x-t.x)==&&sgn(y-t.y)==;
}
ld ang()const
{
return atan2(y,x);
}
ld length()const
{
return sqrt(x*x+y*y);
}
P rotate(const P &t,ld sita)const
{
return {(x-t.x)*cos(sita)-(y-t.y)*sin(sita)+t.x,
(x-t.x)*sin(sita)+(y-t.y)*cos(sita)+t.y};
}
ld btang(const P &t)const
{
return acos( (*this%t)/length()/t.length() );
}
P midvec(const P &t)const
{
return (*this)/length()+t/t.length();
}
}; struct LINE
{
P p1,p2;
void read()
{
p1.read(); p2.read();
}
LINE midLINE()
{
P midp=(p1+p2)/;
P v=p2-p1;
v=v.rotate({,},pi/);
return {midp,midp+v};
}
bool have1(const P &p)const
{
return sgn( (p-p1)*(p-p2) )==&&sgn( (p-p1)%(p-p2) )<=;
}
bool have2(const P &p)const
{
return sgn( (p-p1)*(p-p2) )==&&sgn( (p-p1)%(p2-p1) )>=;
}
bool have3(const P &p)const
{
return sgn( (p-p1)*(p-p2) )==;
}
lod areawith(const P &p)const
{
return abs( (p1-p)*(p2-p)/ );
}
P vecfrom(const P &p)const
{
P v=(p2-p1);
v=v.rotate({,},pi/);
ld s1=(p1-p)*(p2-p);
ld s2=v*(p2-p1);
v=v*(s1/s2);
return v;
}
P footfrom(const P &p)const
{
P v=vecfrom(p);
return p+v;
}
ld dis1from(const P &p)const
{
P foot=footfrom(p);
if (have1(foot)) return (foot-p).length();
return min( (p1-p).length(),(p2-p).length());
}
ld dis2from(const P &p)const
{
P foot=footfrom(p);
if (have2(foot)) return (foot-p).length();
return (p1-p).length();
}
ld dis3from(const P &p)const
{
return vecfrom(p).length();
}
P symP(const P &p)const
{
P v=vecfrom(p);
return p+v*;
}
bool isct11(const LINE &L)const
{
P a1=p1,a2=p2;
P b1=L.p1,b2=L.p2;
if (sgn( max(a1.x,a2.x)-min(b1.x,b2.x) )<||
sgn( max(b1.x,b2.x)-min(a1.x,a2.x) )<||
sgn( max(a1.y,a2.y)-min(b1.y,b2.y) )<||
sgn( max(b1.y,b2.y)-min(a1.y,a2.y) )<)
return ;
lod tmp1=(a2-a1)*(b1-a1);
lod tmp2=(a2-a1)*(b2-a1);
if (sgn(tmp1)<&&sgn(tmp2)<||sgn(tmp1)>&&sgn(tmp2)>) return ;
tmp1=(b2-b1)*(a1-b1);
tmp2=(b2-b1)*(a2-b1);
if (sgn(tmp1)<&&sgn(tmp2)<||sgn(tmp1)>&&sgn(tmp2)>) return ;
return ;
}
bool isct21(const LINE &L)const
{
P v=p2-p1;
P a=p1;
P b1=L.p1,b2=L.p2;
lod tmp1=v*(b1-a);
lod tmp2=v*(b2-a);
if (sgn(tmp1)<&&sgn(tmp2)<||sgn(tmp1)>&&sgn(tmp2)>) return ;
if (tmp1>tmp2) swap(b1,b2);
if (sgn( (b1-a)*(b2-a) )>) return ;
if (sgn( (b1-a)*(b2-a) )<) return ;
return L.have1(a)||have2(b1)||have2(b2);
}
bool isct31(const LINE &L)const
{
P v=p2-p1;
P a=p1;
lod tmp1=v*(L.p1-a);
lod tmp2=v*(L.p2-a);
if (sgn(tmp1)<&&sgn(tmp2)<||sgn(tmp1)>&&sgn(tmp2)>) return ;
return ;
}
bool isct22(const LINE &L)const
{
if (have2(L.p1)||L.have2(p1)) return ;
P v=vecfrom(L.p1);
if (sgn( v%(L.p2-L.p1) )<=) return ;
v=L.vecfrom(p1);
if (sgn( v%(p2-p1) )<=) return ;
return ;
}
bool isct32(const LINE &L)const
{
if (have3(L.p1)) return ;
P v=vecfrom(L.p1);
if (sgn( v%(L.p2-L.p1) )<=) return ;
return ;
}
bool isct33(const LINE &L)const
{
if (have3(L.p1)) return ;
return sgn( (p2-p1)*(L.p2-L.p1) )!=;
}
ld dis33(const LINE &L)const
{
return (L.p1-p1)*(L.p2-p1) / ( (p2-p1)*(L.p2-L.p1) )
* (p2-p1).length();
}
P isctPoint(const LINE &L)const
{
ld len=dis33(L);
P v=p2-p1;
return p1+v*(len/v.length());
} }; const int POLNUM=;
struct PL
{
ld len;
int v;
}stk[POLNUM];
int top;
bool cmplen(const PL &a,const PL &b)
{
return a.len<b.len;
}
P cent;
bool cmpang(const P &p1,const P &p2)
{
int tmp=sgn( (p1-cent).ang() - (p2-cent).ang() );
if (tmp!=) return tmp<;
return (p1-cent).length() < (p2-cent).length();
}
struct POLYGON
{
int n;
P a[POLNUM];
void read(int k)
{
for (int i=;i<=k;i++) a[i].read();
n=k;
}
void ChangetoConvex()
{
for (int i=;i<=n;i++)
if (a[i].x<a[].x||a[i].x==a[].x&&a[i].y<a[].y)
swap(a[],a[i]);
cent=a[];
sort(a+,a+n+,cmpang);
int top=;
for (int i=;i<=n;i++)
{
while(top>=&&
sgn((a[top]-a[top-])*(a[i]-a[top]))<= )
top--;
a[++top]=a[i];
}
n=top;
}
ld Clength()const
{
ld ret=;
for (int i=;i<=n;i++) ret+=(a[i]-a[i-]).length();
if (n>) ret+=(a[]-a[n]).length();
return ret;
}
bool have(const P p)
{
int k,d1,d2,wn=;
a[]=a[n];
for (int i=;i<=n;i++)
{
LINE L={a[i-],a[i]};
if (L.have1(p)) return ;
k=sgn( (a[i]-a[i-])*(p-a[i-]) );
d1=sgn( a[i-].y-p.y );
d2=sgn( a[i].y-p.y );
if (k>&&d1<=&&d2>) wn++;
if (k<&&d2<=&&d1>) wn--;
}
return wn!=;
}
ld cutlength(const LINE &L)
{
a[]=a[n]; top=;
for (int i=;i<=n;i++)
{
LINE R={a[i-],a[i]};
lod s1=sgn( (L.p2-L.p1)*(R.p1-L.p1) );
lod s2=sgn( (L.p2-L.p1)*(R.p2-L.p1) );
if (s1<&&s2<||s1==&&s2==||s1>&&s2>) continue;
if (s1<s2) stk[++top]={L.dis33(R),(s1!=&&s2!=?:)};
else stk[++top]={L.dis33(R),(s1!=&&s2!=?-:-)};
}
sort(stk+,stk+top+,cmplen);
int cnt=;
ld ret=;
for (int i=;i<=top;i++)
{
if (cnt) ret+=stk[i].len-stk[i-].len;
cnt+=stk[i].v;
}
return ret;
}
bool isct(const POLYGON &POL)const
{
for (int i=;i<=n;i++)
for (int j=;j<=POL.n;j++)
{
LINE L1={a[i-],a[i]};
LINE L2={POL.a[j-],POL.a[j]};
if (L1.isct11(L2)) return ;
}
return ;
}
ld isctarea(const POLYGON &POL)const;
}; int T,n,f[];
P p[];
POLYGON a,b;
int init()
{
a.n=b.n=;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
p[i].read();
scanf("%d",&f[i]);
if(f[i]>)a.a[++a.n]=p[i];
else b.a[++b.n]=p[i];
}
if(a.n>b.n)swap(a,b);
if(!a.n)return printf("Successful!\n"),;
if(b.n==)
{
if((a.a[]-b.a[]).length()<eps)return printf("Infinite loop!\n"),;
return printf("Successful!\n"),;
}
b.ChangetoConvex();
for(int i=;i<=a.n;i++)
if(b.have(a.a[i]))return printf("Infinite loop!\n"),;
a.ChangetoConvex();
if(a.isct(b))return printf("Infinite loop!\n"),;
return printf("Successful!\n"),;
}
int main()
{
scanf("%d",&T);
while(T--)init();
return ;
}

[2019HDU多校第一场][HDU 6590][M. Code]的更多相关文章

  1. [2019HDU多校第一场][HDU 6578][A. Blank]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6578 题目大意:长度为\(n\)的数组要求分别填入\(\{0,1,2,3\}\)四个数中的任意一个,有 ...

  2. [2019HDU多校第一场][HDU 6580][C. Milk]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6580 题目大意:\(n\times m\)大小的方格上有\(k\)瓶水,喝完每瓶水都需要一定的时间.初 ...

  3. [2019HDU多校第一场][HDU 6584][G. Meteor]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6584 题目大意:求所有满足\(0<\frac{p}{q}\leq1, gcd(p,q)=1,p\ ...

  4. [2019HDU多校第一场][HDU 6588][K. Function]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6588 题目大意:求\(\sum_{i=1}^{n}gcd(\left \lfloor \sqrt[3] ...

  5. 2019HDU多校第一场1001 BLANK (DP)(HDU6578)

    2019HDU多校第一场1001 BLANK (DP) 题意:构造一个长度为n(n<=10)的序列,其中的值域为{0,1,2,3}存在m个限制条件,表示为 l r x意义为[L,R]区间里最多能 ...

  6. [2019HDU多校第二场][HDU 6591][A. Another Chess Problem]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6591 题目大意:二维坐标系上,所有满足\(5|2x+y\)的点都被设为障碍物,无法通过.现给出一对点, ...

  7. 2019HDU多校第一场 BLANK DP

    题意:有四种数字,现在有若干个限制条件:每个区间中不同的数字种类必须是多少种,问合法的方案数. 思路: 定义 dp[i][j][k][t] 代表填完前 t 个位置后,{0,1,2,3} 这 4 个数字 ...

  8. 2019HDU多校第一场 String 贪心

    题意:给你一个字符串,问是否存在一个长度为m的子序列,子序列中对应字符的数目必须在一个范围内,问是否存在这样的字符串?如果存在,输出字典序最小的那个. 思路:贪心,先构造一个序列自动机,序列自动机指向 ...

  9. 2019HDU多校第一场 6582 Path 【最短路+最大流最小割】

    一.题目 Path 二.分析 首先肯定要求最短路,然后如何确定所有的最短路其实有多种方法. 1 根据最短路,那么最短路上的边肯定是可以满足$dist[from] + e.cost = dist[to] ...

随机推荐

  1. sql数据库的基础语句

    1, 创建数据库 create database database-name 2, 删除数据库 drop database dbname 3, 备份sql server 创建 备份数据的device ...

  2. java版MD5签名工具类

    package com.net.util; import java.security.MessageDigest; /** * MD5签名工具类 * @author zhangdi * */ publ ...

  3. SSM+pagehelper分页

    1.maven依赖 <dependency> <groupId>com.github.jsqlparser</groupId> <artifactId> ...

  4. if (strAreaCode.Find("体检")>=0)

    string类提供了6种查找函数,每种函数以不同形式的find命名. 这些操作全部返回string::size_type类型的值,以下形式标记查找匹配所发生的位置: 或者返回一个名为string::n ...

  5. LC 20 Valid Parentheses

    问题 Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the i ...

  6. Photon Server 实现注册与登录(三) --- 前端UI设计和发起请求

    一.打开之前的测试项目.先将服务端代码编译一下,在 bin/Debug/目录下会发现有一个Common.dill.我们相应导入到前端使用.直接拖拽到相应地方 UI相应布局属于前端操作,这里就不做介绍了 ...

  7. MyBatis 源码篇-插件模块

    本章主要描述 MyBatis 插件模块的原理,从以下两点出发: MyBatis 是如何加载插件配置的? MyBatis 是如何实现用户使用自定义拦截器对 SQL 语句执行过程中的某一点进行拦截的? 示 ...

  8. React virtual DOM explained in simple English/简单语言解释React的虚拟DOM

    初学React,其中一个很重要的概念是虚拟DOM,看了一篇文章,顺带翻译一下. If you are using React or learning React, you must have hear ...

  9. 路由器WAN口IP显示为10、100、172开头,网络被电信联通等运营商做了NAT转发

    摘要:路由器WAN口IP显示为10.100.172开头,网络被电信联通等运营商做了NAT转发 ... 路由器WAN口IP显示为10.100.172开头的解决方法方法一:找电信(10000号)或者联通( ...

  10. 使用 function 构造函数创建组件和使用 class 关键字创建组件

    使用 function 构造函数创建组件: 如果想要把组件放到页面中,可以把构造函数的名称,当作 组件的名称,以 HTML标签形式引入页面中, 因为在React中,构造函数就是一个最基本的组件. 注意 ...