题意:给定一条折线,问能否在不扭曲它的情况下让它完全通过一个小孔

这个条件就是:过折线上任意一点$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的更多相关文章

  1. [LeetCode] Design Snake Game 设计贪吃蛇游戏

    Design a Snake game that is played on a device with screen size = width x height. Play the game onli ...

  2. Leetcode: Design Snake Game

    Design a Snake game that is played on a device with screen size = width x height. Play the game onli ...

  3. 2101 Problem A Snake Filled

    题目描述 “What a boring world!”Julyed felt so bored that she began to write numbers on the coordinate pa ...

  4. 图像分割之(五)活动轮廓模型之Snake模型简介

    在"图像分割之(一)概述"中咱们简单了解了目前主流的图像分割方法.下面咱们主要学习下基于能量泛函的分割方法.这里学习下Snake模型简单的知识,Level Set(水平集)模型会在 ...

  5. Epic - Snake Sequence

    You are given a grid of numbers. A snakes equence is made up of adjacent numbers such that for each ...

  6. 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 ...

  7. 图像切割之(五)活动轮廓模型之Snake模型简单介绍

    图像切割之(五)活动轮廓模型之Snake模型简单介绍 zouxy09@qq.com http://blog.csdn.net/zouxy09 在"图像切割之(一)概述"中咱们简单了 ...

  8. 353. Design Snake Game

    贪食蛇. GAME OVER有2种情况,1是咬到自己,2是出界. 1)用QUEUE来保留占据的格子,每走一格就添加1个,然后POll()最后一个. 做一个一样的SET来check要走的格子是不是已经在 ...

  9. 切割图像(五)主动轮廓模型Snake简要模型

    切割图像(五)主动轮廓模型Snake简要模型 zouxy09@qq.com http://blog.csdn.net/zouxy09 在"图像切割之(一)概述"中咱们简单了解了眼下 ...

随机推荐

  1. hdu 1150 Machine Schedule(二分匹配,简单匈牙利算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 Machine Schedule Time Limit: 2000/1000 MS (Java/ ...

  2. feign hystrix 线程池伸缩控制

    当前使用的版本 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spr ...

  3. shell下在while循环中使用ssh命令的问题

    1 现象描述 最近使用ssh批量执行命令(已经做了密钥互信了),脚本读取配置文件中的主机列表(内容为每行一台主机IP地址),然后执行,可是每次只是执行第一台,就退出循环了. 2 排查思路 由于脚本比较 ...

  4. 前端—css

    css css概述 CSS是Cascading Style Sheets的简称,中文称为层叠样式表,用来控制网页数据的表现,可以使网页的表现与数据内容分离. 一.css的四种引入方式: 1.行内式   ...

  5. Linux 入门记录:十八、Linux 系统启动流程 + 单用户修改 root 密码 + GRUB 加密

    一.系统启动流程 一般来说,Linux 系统的启动流程是这样的: 1. 开机之后,位于计算机主板 ROM 芯片上的 BIOS 被最先读取,在进行硬件和内存的校验以及 CPU 的自检没有异常后, BIO ...

  6. 天气api接口

    python调用天气api接口: http://www.sojson.com/open/api/weather/json.shtml?city=北京 http://www.sojson.com/blo ...

  7. 【jzoj6.24模拟B】

    这场真是无聊,搬远古原题…… xjb做了做,(居然没AK真是身败名裂) A.教主的花园 答案明显具有可二分性,二分答案判定下就行. #include<bits/stdc++.h> #def ...

  8. Python爬虫音频数据

    一:前言 本次爬取的是喜马拉雅的热门栏目下全部电台的每个频道的信息和频道中的每个音频数据的各种信息,然后把爬取的数据保存到mongodb以备后续使用.这次数据量在70万左右.音频数据包括音频下载地址, ...

  9. 亚马逊EC2根硬盘空间扩容

    买的系统盘为32G,结果发现只使用了8G,剩下的都未分配 lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda : 32G disk └─xvda1 : ...

  10. Leetcode 之Count and Say(35)

    很有意思的一道题,不好想啊. string getNext(string &s) { ]; ; stringstream ss; ; i < s.size(); i++) { if (s ...