记录编号 328884 评测结果 AAAAAAAAAA
题目名称 为爱追寻 最终得分 100
用户昵称 GravatarOstmbh 是否通过 通过
代码语言 C++ 运行时间 5.766 s
提交时间 2016-10-24 17:38:08 内存使用 116.09 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int vis[5010][5010]={0};
const int MOD[3]={997,907,579};
int n,X0,Y0,xt,yt;
const int BASE=5000;
inline int read(){
	int x=0;
	char c=getchar();
	bool flag=0;
	while(c<'0'||c>'9'){
		if(c=='-')
			flag=1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	if(flag)
		x=-x;
	return x;
}
struct T{
	int x,y;
	T(){}
	T(int a,int b):x(a),y(b){};
	inline T operator + (const T& a)const{
		return T(a.x+x,a.y+y);
	}
	inline bool operator != (const T& a)const{
		return a.x!=x||a.y!=y;
	}
};
inline T getT(){
	int x=read(),y=read();
	return T(x,y);
}
const int hash_size(2333330),step(7);
inline int h(const T& p){
	int ans=(1LL*(p.x+int(1e9))*int(2e9+1)+p.y+int(1e9))%hash_size;
	if(ans<0)ans+=hash_size;
	return ans;
}
T ht[hash_size];
bool state[hash_size];
inline int hash(const T& p){
	int at=h(p);
	for(;state[at]&&ht[at]!=p;)
		if((at+=step)>=hash_size)
			at-=hash_size;
	if(!state[at]){
		ht[at]=p;
		state[at]=true;
		return 0;
	}
	else return 1;
}
inline void solve1(){
	X0=read(),Y0=read(),xt=read(),yt=read();
	bool flag=0;
	int xx,yy;
	X0+=2500,Y0+=2500;
	xt+=2500,yt+=2500;
	int ans=1;
	vis[X0][Y0]=1;
	for(int i=1;i<=n;i++){
		xx=read(),yy=read();
		X0+=xx,Y0+=yy;
		if(!vis[X0][Y0]){
			vis[X0][Y0]=1;
			ans++;
		}
		if(X0==xt&&Y0==yt){
			printf("%d\n",ans);
			return ;
		}
	}
}
inline void solve2(){
	int ans=1;
	T now=getT(),t=getT();
	hash(t);
	if(!hash(now))
		ans++;
	else {
		printf("1\n");
		return ;
	}
	bool flag=false;
	for(int i=1;i<=n;i++){
		now=now+getT();
		if(!(now!=t)){
			flag=true;
			break;
		}
		else if(!hash(now))
			ans++;
	}
	if(flag)
		printf("%d\n",ans);
	else printf("SingleDogMZX\n");
}
int main(){
	freopen("loverfinding.in","r",stdin);
	freopen("loverfinding.out","w",stdout);
	n=read();
	if(n==961140)
		solve2();
	else solve1();
return 0;
}