比赛 NOIP模拟赛by mzx Day1 评测结果 TTTTTTTTTT
题目名称 为爱追寻 最终得分 0
用户昵称 FoolMike 运行时间 10.016 s
代码语言 C++ 内存使用 137.56 MiB
提交时间 2016-10-19 21:56:18
显示代码纯文本
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=20000010,p=20000007;
inline int read(){
	int x=0;bool sign=1;char ch=getchar();
	while ((ch>'9'||ch<'0')&&ch!='-') ch=getchar();
	if (ch=='-') sign=0,ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return sign?x:-x;
}
struct point{
	int x,y;
	point(int X=0,int Y=0){x=X;y=Y;}
	bool operator == (const point a){return x==a.x&&y==a.y;}
	void operator += (const point a){x+=a.x;y+=a.y;}
}s,v,t,sit[N];
int n,m,cnt;bool vis[N];
inline int abs(int x){return x>0?x:-x;}
inline void hash(point x){
	int ans=0;
	for (int i=abs(x.x);i;i/=47) ans=(ans*127+61)%p;
	for (int i=abs(x.y);i;i/=47) ans=(ans*127+61)%p;
	while (!(sit[ans]==x)&&vis[ans]) ans=(ans==p?0:ans+1);
	if (!vis[ans]) vis[ans]=1,sit[ans]=x,cnt++;
}
int main()
{
	freopen("loverfinding.in","r",stdin);
	freopen("loverfinding.out","w",stdout);
	scanf("%d%d%d%d%d",&n,&s.x,&s.y,&t.x,&t.y);
	hash(point(0,0));
	if (s==t){printf("%d\n",cnt);return 0;}
	for (int i=1;i<=n;i++){
		v.x=read();v.y=read();
		s+=v;hash(s);
		if (s==t){printf("%d\n",cnt);return 0;}
		//printf("%d\n",i);
	}
	printf("SingleDogMZX\n");
	return 0;
}