E. Vanya and Field

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/492/problem/E

Description

Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates(xi, yi). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell . The following condition is satisfied for the vector: , where  is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.

Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.

Input

The first line contains integers n, m, dx, dy(1 ≤ n ≤ 106, 1 ≤ m ≤ 105, 1 ≤ dx, dy ≤ n) — the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers xi, yi (0 ≤ xi, yi ≤ n - 1) — the coordinates of apples. One cell may contain multiple apple trees.

Output

Print two space-separated numbers — the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.

Sample Input

  1. 5 5 2 3
    0 0
    1 2
    1 3
    2 4
    3 1

Sample Output

  1. 1 3

HINT

题意

有一个n*n的方格,有m棵苹果树

一开始假设在(x,y),那么下一次可以在(x+dx,y+dy)位置,可以无限走

然后问你起点定在什么位置,可以如果最多的苹果树

题解:

题目说了,gcd(n,dx)=0,那么很显然,这个集合里面有n个元素(这个可以用exgcd证明

那么也很容易证明,每一行的每个元素都属于不同的集合

然后我们就可以先暴力找到一个集合,然后这个苹果树和这个集合偏移多少,那么这个苹果树就属于第几个集合

代码

  1. #include<iostream>
  2. #include<stdio.h>
  3. using namespace std;
  4. #define maxn 1000006
  5. int X[maxn];
  6. int ans[maxn];
  7. int main()
  8. {
  9. int n,m,dx,dy;
  10. scanf("%d%d%d%d",&n,&m,&dx,&dy);
  11. int xx=,yy=;
  12. for(int i=;i<n;i++)
  13. {
  14. X[xx]=yy;
  15. xx+=dx;
  16. yy+=dy;
  17. if(xx>=n)xx-=n;
  18. if(yy>=n)yy-=n;
  19. }
  20. int ans1=,ans2=,ans3=;
  21. for(int i=;i<m;i++)
  22. {
  23. int x,y;scanf("%d%d",&x,&y);
  24. int tmp = y-X[x];if(tmp<)tmp+=n;
  25. ans[tmp]++;
  26. if(ans[tmp]>=ans3)
  27. {
  28. ans3=ans[tmp];
  29. ans1=,ans2=tmp;
  30. }
  31. }
  32. printf("%d %d\n",ans1,ans2);
  33.  
  34. }

Codeforces Round #280 (Div. 2) E. Vanya and Field 数学的更多相关文章

  1. Codeforces Round #280 (Div. 2)E Vanya and Field(简单题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 本场题目都比较简单,故只写了E题. E. Vanya and Field Vany ...

  2. Codeforces Round #280 (Div. 2) E. Vanya and Field 思维题

    E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 二分

    D. Vanya and Computer Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  4. Codeforces Round #280 (Div. 2) C. Vanya and Exams 贪心

    C. Vanya and Exams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/492/pr ...

  5. Codeforces Round #280 (Div. 2)_C. Vanya and Exams

    C. Vanya and Exams time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  6. Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 预处理

    D. Vanya and Computer Game time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  7. Codeforces Round #280 (Div. 2) A. Vanya and Cubes 水题

    A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  8. Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 数学

    D. Vanya and Computer Game time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  9. Codeforces Round #308 (Div. 2)B. Vanya and Books 数学

    B. Vanya and Books Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/pr ...

随机推荐

  1. 【Unity3D】生成工程报错解决—UnityEditor.HostView:OnGUI() Error building Player: Couldn't build player because of unsupported data on target platform.

    错误 错误1:An asset is marked as dont save, but is included in the build: unityEditor.HostView:OnGUI() 错 ...

  2. 【RMQ问题】求数组区间最大值,NYOJ-1185-最大最小值

    转自:http://blog.csdn.net/lilongherolilong/article/details/6624390 先挖好坑,明天该去郑轻找虐 RMQ(Range Minimum/Max ...

  3. Hadoop中OutputFormat解析

    一.OutputFormat OutputFormat描述的是MapReduce的输出格式,它主要的任务是: 1.验证job输出格式的有效性,如:检查输出的目录是否存在. 2.通过实现RecordWr ...

  4. Linux+Apache+Tomcat集群配置

    参考: http://blog.csdn.net/bluishglc/article/details/6867358# http://andashu.blog.51cto.com/8673810/13 ...

  5. SQL Server缺省约束、列约束和表约束

    SQL Server缺省约束是SQL Server数据库中的一种约束,下面就为您介绍SQL Server缺省约束.列约束和表约束的定义方法啊,供您参考. SQL Server缺省约束 SQL Serv ...

  6. 取requests返回字典值用json()

    python模块requests返回值用json()["h"][key]可以取出下面的value

  7. JQuery插件之图片轮播插件–slideBox

    来源:http://www.ido321.com/852.html 今天偶然发现了一个比较好用的图片轮播插件—slideBox 先看看效果:http://slidebox.sinaapp.com/ 代 ...

  8. java 复习002

    java东西太多了,我都有点小凌乱了,记得太没结构了 java内存回收机制:垃圾收集GC(Garbage Collection) 两种常用方法: 引用计数(早期使用) 简介:堆中对象每次被栈中引用指向 ...

  9. SQL Server 2000的并发连接数是多少

    开始->管理工具->性能(或者是运行里面输入 mmc)然后通过 添加计数器添加 SQL 的常用统计(MSSQL General Statistics) 然后在下面列出的项目里面选择 用户连 ...

  10. Codevs No.1281 Xn数列

    2016-06-01 16:28:25 题目链接: Xn数列 (Codevs No.1281) 题目大意: 给定一种递推式为 Xn=(A*Xn-1+C)%M 的数列,求特定的某一项%G 解法: 矩阵乘 ...