记录编号 200625 评测结果 AAAAAAAAAA
题目名称 Yukari 最终得分 100
用户昵称 GravatarSkyo 是否通过 通过
代码语言 C++ 运行时间 0.280 s
提交时间 2015-10-29 07:33:06 内存使用 4.10 MiB
显示代码纯文本
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;

int n, xl, xr, yl, yr, maxt, pos;
int ans[1000005];

int calc(int &tl, int &tr, int x, int y, int u, int v)
{
	int tl1, tr1, tl2, tr2; tl1 = tl2 = 1<<30, tr1 = tr2 = -(1<<30);
	if(x < xl)
	{
		if(u > 0)
		{
			tl1 = max(0, (xl-x)/u-2);
			while(x+u*tl1 < xl) tl1++;
			tr1 = (xr-x)/u+2;
			while(x+u*tr1 > xr) tr1--;
		}
	}
	else if(x > xr)
	{
		if(u < 0)
		{
			tl1 = max(0, (xr-x)/u-2);
			while(x+u*tl1 > xr) tl1++;
			tr1 = (xl-x)/u+2;
			while(x+u*tr1 < xl) tr1--;
		}
	}
	else 
	{
		tl1 = 0;	
		if(u > 0)
		{
			tr1 = (xr-x)/u+2;
			while(x+u*tr1 > xr) tr1--;
		}
		if(u < 0)
		{
			tr1 = (xl-x)/u+2;
			while(x+u*tr1 < xl) tr1--;
		}
	}
	if(y < yl)
	{
		if(v > 0)
		{
			tl2 = max(0, (yl-y)/v-2);
			while(y+v*tl2 < yl) tl2++;
			tr2 = (yr-y)/v+2;
			while(y+v*tr2 > yr) tr2--;
		}
	}
	else if(y > yr)
	{
		if(v < 0)
		{
			tl2 = max(0, (yr-y)/v-2);
			while(y+v*tl2 > yr) tl2++;
			tr2 = (yl-y)/v+2;
			while(y+v*tr2 < yl) tr2--;
		}
	}
	else 
	{
		tl2 = 0;	
		if(v > 0)
		{
			tr2 = (yr-y)/v+2;
			while(y+v*tr2 > yr) tr2--;
		}
		if(v < 0)
		{
			tr2 = (yl-y)/v+2;
			while(y+v*tr2 < yl) tr2--;
		}
	}
	tl = max(tl1, tl2);
	tr = min(tr1, tr2);
	if(tl > tr) tr = -1, tl = 0;
}

int main()
{
	freopen("camera.in", "r", stdin);
	freopen("camera.out", "w", stdout);
	scanf("%d %d %d %d %d", &n, &xl, &yl, &xr, &yr);
	for(int i = 1; i <= n; i++)
	{
		int tl = 0, tr = 0, x, y, u, v; 
		scanf("%d %d %d %d", &x, &y, &u, &v);
		calc(tl, tr, x, y, u, v);
		ans[tl]++, ans[tr+1]--;
		maxt = max(maxt, tr);
	}
	for(int i = 1; i <= maxt; i++) ans[i] += ans[i-1];
	for(int i = 1; i <= maxt; i++)
		if(ans[i] > ans[pos]) pos = i;
	printf("%d", pos);
	return 0;
}