记录编号 386009 评测结果 AAAAAAAAAA
题目名称 [HAOI 2014]穿越封锁线 最终得分 100
用户昵称 GravatarkZime 是否通过 通过
代码语言 C++ 运行时间 0.001 s
提交时间 2017-03-23 08:56:13 内存使用 0.31 MiB
显示代码纯文本
/*kZime*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <algorithm>
#define MAXN 55
using namespace std;
inline int read() {
	int k = 0, f = 1; char c = getchar();
	for(; !isdigit(c); c = getchar())if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
	return k * f;
}
/*-----------------------------------------------------------------------------*/

class edge{
public:
	double k, b;
	int xf, xt;
	void in(int x1, int y1, int x2, int y2) {
		if(x1 > x2) {
			swap(x1, x2);
			swap(y1, y2);
		}
		k = (double)(y2 - y1) / (x2 - x1);
		b = (double)y1 - k * x1;
		xf = x1;
		xt = x2;
	}
}e[MAXN];

int n, en, xn, yn, xb, yb, x, y;
double ans;
vector<double> py;//交点的y值

int main() {
#ifndef MYLAB
	freopen("ha14b.in", "r", stdin);
	freopen("ha14b.out", "w", stdout);
#else
	freopen("in.txt", "r", stdin);
#endif
	n = read();
	int tep1 = xb = read();
	int tep2 = yb = read();
	for(int i = 2; i <= n; i++) {
		xn = read();
		yn = read();
		e[++en].in(xb, yb, xn, yn);
		xb = xn;
		yb = yn;
	}
	e[++en].in(xb, yb, tep1, tep2);
	
	
	
	x = read();
	y = read();
	
//	for(int i = 1; i <= en; i++) {
//		printf("k = %.3llf  b = %.3llf\n", e[i].k, e[i].b);
//	}
	
	for(int i = 1; i <= en; i++) {
		if(e[i].xf > x || e[i].xt < x) continue;
		
		if(e[i].k * x + e[i].b >= (double)y) {
			py.push_back((double)e[i].k * x + e[i].b);
		}
	}

//	for(int i = 0; i < py.size(); i++) {
//		printf("%llf ", py[i]);
//	}

	sort(py.begin(), py.end());
	
//	for(int i = 0; i < py.size(); i++) {
//		printf("%llf ", py[i]);
//	}
	if(py.size()%2) py.pop_back();
	for(int i = 0; i < py.size(); i += 2) {
		double ly = py[i];
		double ky = py[i + 1];
		ans += ky - ly;
	}
	
	printf("%d", (int)ans);

	return 0;
}
/*
8
4 1
3 2
4 4
3 4
2 5
2 3
0 1
2 0
3 -1

5         5

4              4    3

3         6

2              2

17                  1

0    1    28   3    4    5

			  000


*/