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

这个条件就是:过折线上任意一点$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. error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'

    error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'System. ...

  2. 比 file_get_contents() 更优的 cURL 详解(附实例)

    PHP 可以使用 file_get_content() 函数抓取网页内容,但却无法进行更复杂的处理,譬如文件的上传或下载. Cookie 操作等等.而 cURL 提供了这些功能. 一.cURL简介 在 ...

  3. python基础===Excel处理库openpyxl

    openpyxl是一个第三方库,可以处理xlsx格式的Excel文件. 安装: pip install openpyxl 对如下excel进行读取操作,如图: from openpyxl import ...

  4. linux===linux后台运行和关闭、查看后台任务(转)

    fg.bg.jobs.&.ctrl + z都是跟系统任务有关的,虽然现在基本上不怎么需要用到这些命令,但学会了也是很实用的 一.& 最经常被用到这个用在一个命令的最后,可以把这个命令放 ...

  5. sicily 1001. Fibonacci 2

    1001. Fibonacci 2   Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn-1 + F ...

  6. C后端设计开发 - 第3章-气功-原子锁线程协程

    正文 第3章-气功-原子锁线程协程 后记 如果有错误, 欢迎指正. 有好的补充, 和疑问欢迎交流, 一块提高. 在此谢谢大家了. 童话镇 - http://music.163.com/#/m/song ...

  7. [New Learn]被嫌弃的app的一生

    1.简介 为什么叫被嫌弃的app的一生?致敬电影<被嫌弃的松子的一生>. 自学IOS东一锄西一镐的总感觉没有一个总的概念,还是多看看官网吧,先看一下一个app的整个生命周期,本文主要是翻译 ...

  8. Median_of_Two_Sorted_Arrays(理论支持和算法总结)

    可以将这个题目推广到更naive的情况,找两个排序数组中的第K个最大值(第K个最小值). 1.直接 merge 两个数组,然后求中位数(第K个最大值或者第K个最小值),能过,不过复杂度是 O(n + ...

  9. 使用 Visual Studio 部署 .NET Core 应用

    可将 .NET Core 应用程序部署为依赖框架的部署或独立部署,前者包含应用程序二进制文件,但依赖目标系统上存在的 .NET Core,而后者同时包含应用程序和 .NET Core 二进制文件. 有 ...

  10. Django Ajax学习二之文件上传

    基于Django实现文件上传 1. url路由配置 路径:C:\Users\supery\Desktop\day82\demo_ajax\demo_ajax\urls.py from django.c ...