比赛 NOIP模拟赛by mzx Day1 评测结果 AAAWWWEEEE
题目名称 为爱追寻 最终得分 30
用户昵称 sro dydxh orz 运行时间 4.464 s
代码语言 C++ 内存使用 76.61 MiB
提交时间 2016-10-19 19:21:28
显示代码纯文本
  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdio>
  4. #include<string>
  5. #include<algorithm>
  6. #include<cmath>
  7. #include<utility>
  8. #include<stdio.h>
  9. #include<cstdlib>
  10. #include<iomanip> //cout<<setiosflags(ios::fixed)<<setprecision(2);
  11. #include<ctime> //double a=(double)clock(); cout<<a<<endl;
  12. #include<vector>
  13. #include<queue>
  14. using namespace std;
  15. const int MOD=9999997,step=7,muti_x=631,muti_y=1031;
  16. int n,xo,yo,xt,yt,same;
  17. struct hash
  18. {
  19. int x,y;
  20. }h[10000002];
  21. void insert(int xx,int yy)
  22. {
  23. int at=(1LL*xx*muti_x+1LL*yy*muti_y)%MOD;
  24. while(1)
  25. {
  26. if(h[at].x==-1&&h[at].y==-1)
  27. break;
  28. if(h[at].x==xx&&h[at].y==yy)
  29. break;
  30. at+=step;
  31. if(at>MOD)
  32. at-=MOD;
  33. }
  34. if(h[at].x==xx&&h[at].y==yy)
  35. same--;
  36. h[at].x=xx,h[at].y=yy;
  37. //cout<<same<<endl;
  38. }
  39. void init(){
  40. for(int i=0;i<=10000000;i++)
  41. h[i].x=h[i].y=-1;
  42. }
  43.  
  44. int main()
  45. {
  46. freopen("loverfinding.in","r",stdin);
  47. freopen("loverfinding.out","w",stdout);
  48. init();
  49. scanf("%d%d%d%d%d",&n,&xo,&yo,&xt,&yt);
  50. for(int i=1;i<=n;i++){
  51. //cout<<i<<endl;
  52. int dx,dy;
  53. scanf("%d%d",&dx,&dy);
  54. xo+=dx;//
  55. yo+=dy;//
  56. if(xo==xt&&yo==yt)break;
  57. same++;
  58. insert(xo,yo);
  59. }
  60. cout<<same+2<<endl;
  61. //fclose(stdin),fclose(stdout);
  62. return 0;
  63. }