记录编号 385323 评测结果 AAAAAAAAAA
题目名称 [HAOI 2014]穿越封锁线 最终得分 100
用户昵称 GravatarJustWB 是否通过 通过
代码语言 C++ 运行时间 0.001 s
提交时间 2017-03-20 20:34:04 内存使用 1.28 MiB
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
int n;
int now[2];
int dian[1001][2];
double A,B,all;
bool pan;
bool Pan[1001][1001];
priority_queue<double> dj;
void ji(int i,int j)
{
	double x=dian[i][0]-dian[j][0];
	double y=dian[i][1]-dian[j][1];
	double xl=y/x;
	double b=dian[i][1]-xl*dian[i][0];
	double yy=xl*now[0]+b;
	dj.push(yy);
}
int main()
{
	freopen("ha14b.in","r",stdin);
	freopen("ha14b.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&dian[i][0],&dian[i][1]);
	}
	scanf("%d%d",&now[0],&now[1]);
	for(int i=1;i<=n;i++)
	{
		int j=i+1;
		if(j>n)j=1;
		if(dian[i][0]==now[0])
		{
			if(dian[j][0]==dian[i][0])
			{
				Pan[dian[i][1]][dian[j][1]]=1;
				Pan[dian[i][1]][dian[j][1]]=1;
			}
			dj.push(dian[i][1]);
			dj.push(dian[i][1]);
			continue;
		}
		if(dian[i][0]>now[0]&&dian[j][0]<now[0])
		{
			ji(i,j);
		}
		if(dian[i][0]<now[0]&&dian[j][0]>now[0])
		{
			ji(i,j);
		}
	}
	if(dj.size()%2==1)pan=1;
	//printf("%d",dj.size());
	while(!dj.empty())
	{
		A=dj.top();
		dj.pop();
		B=dj.top();
		int a=A,b=B;
		if(Pan[a][b]&&!pan)
		{
			if(pan)pan=0;
			else{pan=1;}
			continue;
		}
		if(Pan[b][a]&&!pan)
		{
			if(pan)pan=0;
			else{pan=1;}
			continue;
		}
		if(pan)
		{
			pan=0;continue;
		}
		all+=abs(A-B);
		pan=1;
	}
	int ALL=all;
	printf("%d",ALL);
	return 0;
}