[xsy2238]snake
题意:给定一条折线,问能否在不扭曲它的情况下让它完全通过一个小孔
这个条件就是:过折线上任意一点$x$存在一条直线把折线分成不与直线相交的两部分,换句话说存在(与折线只有一个交点$x$)的直线
结论是:若点$i$严格在点$1\cdots i$或点$i\cdots n$构成的凸包内,则无解,因为过点$i$的直线必然与折线在其他的某些位置相交
所以我们可以用set维护仅插入动态凸包,边插入边查询即可
实际上没有必要维护整个凸包,只维护原来的点还有它关于原点对称点的上凸壳就可以了
注意C++做布尔运算的短路机制==
#include<stdio.h>
#include<set>
using namespace std;
typedef long long ll;
struct point{
int x,y;
point(int a=0,int b=0){x=a;y=b;}
}p[100010];
point operator-(point a,point b){return point(a.x-b.x,a.y-b.y);}
ll operator*(point a,point b){return(ll)a.x*b.y-(ll)a.y*b.x;}
struct cmp{
bool operator()(point a,point b){return a.x==b.x?a.y<b.y:a.x<b.x;}
};
struct conv{
typedef set<point,cmp> st;
typedef st::iterator si;
st s;
si it;
si pre(si i){
i--;
return i;
}
si nex(si i){
i++;
return i;
}
point d[100010];
int M,siz;
void clear(){s.clear();siz=0;}
bool insert(point p){
it=s.lower_bound(p);
if(it!=s.begin()&&it!=s.end()&&(p-*pre(it))*(*it-p)>=0)return 0;
M=0;
if(it!=s.begin()){
it--;
while(it!=s.begin()&&(*it-*pre(it))*(p-*it)>=0)d[++M]=*(it--);
}
it=s.lower_bound(p);
if(it!=s.end()){
while(nex(it)!=s.end()&&(*it-p)*(*nex(it)-*it)>=0)d[++M]=*(it++);
}
while(M)s.erase(d[M--]);
s.insert(p);
siz=s.size();
return 1;
}
}c1,c2;
int n;
void work(){
int i;
bool f1,f2;
for(i=1;i<=n;i++)scanf("%d%d",&p[i].x,&p[i].y);
c1.clear();
c2.clear();
for(i=1;i<=n;i++){
f1=!c1.insert(p[i]);
f2=!c2.insert(0-p[i]);
if(f1&&f2){
puts("Impossible");
return;
}
}
c1.clear();
c2.clear();
for(i=n;i>0;i--){
f1=!c1.insert(p[i]);
f2=!c2.insert(0-p[i]);
if(f1&&f2){
puts("Impossible");
return;
}
}
puts("Possible");
}
int main(){
while(~scanf("%d",&n))work();
}
[xsy2238]snake的更多相关文章
- [LeetCode] Design Snake Game 设计贪吃蛇游戏
Design a Snake game that is played on a device with screen size = width x height. Play the game onli ...
- Leetcode: Design Snake Game
Design a Snake game that is played on a device with screen size = width x height. Play the game onli ...
- 2101 Problem A Snake Filled
题目描述 “What a boring world!”Julyed felt so bored that she began to write numbers on the coordinate pa ...
- 图像分割之(五)活动轮廓模型之Snake模型简介
在"图像分割之(一)概述"中咱们简单了解了目前主流的图像分割方法.下面咱们主要学习下基于能量泛函的分割方法.这里学习下Snake模型简单的知识,Level Set(水平集)模型会在 ...
- Epic - Snake Sequence
You are given a grid of numbers. A snakes equence is made up of adjacent numbers such that for each ...
- Codeforces Round #290 (Div. 2) A. Fox And Snake 水题
A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...
- 图像切割之(五)活动轮廓模型之Snake模型简单介绍
图像切割之(五)活动轮廓模型之Snake模型简单介绍 zouxy09@qq.com http://blog.csdn.net/zouxy09 在"图像切割之(一)概述"中咱们简单了 ...
- 353. Design Snake Game
贪食蛇. GAME OVER有2种情况,1是咬到自己,2是出界. 1)用QUEUE来保留占据的格子,每走一格就添加1个,然后POll()最后一个. 做一个一样的SET来check要走的格子是不是已经在 ...
- 切割图像(五)主动轮廓模型Snake简要模型
切割图像(五)主动轮廓模型Snake简要模型 zouxy09@qq.com http://blog.csdn.net/zouxy09 在"图像切割之(一)概述"中咱们简单了解了眼下 ...
随机推荐
- 关于 zfs 命令相关介绍
三种设备:filesystem volume snapshot 1.zfs listroot@UA4300D-spa:~/hanhuakai/pro_07/git_0708# zfs listNA ...
- perl模拟登录(1)
use WWW::Mechanize; my $ua = WWW::Mechanize->new(); $ua->post('http://localhost/dvwa/DVWA-mast ...
- monkey测试===ios-monkey测试工具
iOSmonkey测试工具: crashmonkey 特点: 支持**真机测试.模拟器测试** 支持收集**系统日志(Systemlog)**.**崩溃日志(Crashlog)**.***instru ...
- linux-open-source-development-tools【重点】
https://www.pluralsight.com/blog/software-development/linux-open-source-development-tools https://ww ...
- 【bzoj1923】外星千足虫
这个gauss消元有点naive啊. 由于只有01,位操作显然是方便的多. 那么用bitset代替之前的增广矩阵就行了. #include<bits/stdc++.h> #define N ...
- caffe Python API 之卷积层(Convolution)
1.Convolution层: 就是卷积层,是卷积神经网络(CNN)的核心层. 层类型:Convolution lr_mult: 学习率的系数,最终的学习率是这个数乘以solver.prototxt配 ...
- 使用js获取url里的指定参数
String.prototype.getQuery = function(name){ var reg = new RegExp("(^|&)"+ name +&q ...
- python_基于反射模拟Web框架路由系统
根据用户输入的内容,导入模块 #根据用户输入的内容,导入模块 inp = input("请输入模块名: ") print(inp,type(inp)) dd = __import_ ...
- Django 定制验证码
一.图片验证码 方式一: def get_validCode_img(request): path=os.path.join(settings.BASE_DIR,'static','image','1 ...
- AC日记——小B的询问 洛谷 P2709
小B的询问 思路: 水题: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 50005 #define ll ...