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

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

Sample Output

1 3

HINT

题意

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

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

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

题解:

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

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

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

代码

#include<iostream>
#include<stdio.h>
using namespace std;
#define maxn 1000006
int X[maxn];
int ans[maxn];
int main()
{
int n,m,dx,dy;
scanf("%d%d%d%d",&n,&m,&dx,&dy);
int xx=,yy=;
for(int i=;i<n;i++)
{
X[xx]=yy;
xx+=dx;
yy+=dy;
if(xx>=n)xx-=n;
if(yy>=n)yy-=n;
}
int ans1=,ans2=,ans3=;
for(int i=;i<m;i++)
{
int x,y;scanf("%d%d",&x,&y);
int tmp = y-X[x];if(tmp<)tmp+=n;
ans[tmp]++;
if(ans[tmp]>=ans3)
{
ans3=ans[tmp];
ans1=,ans2=tmp;
}
}
printf("%d %d\n",ans1,ans2); }

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. 【转】android Apk打包过程概述_android是如何打包apk的

    最近看了老罗分析android资源管理和apk打包流程的博客,参考其他一些资料,做了一下整理,脱离繁琐的打包细节和数据结构,从整体上概述了apk打包的整个流程.   流程概述: 1.打包资源文件,生成 ...

  2. 利用ASP.NET MVC源代码调试你的应用程序[转]

    由于项目需要,最近学起asp.net mvc.昨天遇到ViewData和TempData他们之间的分别这样让我纠结的问题.有园友强烈建议我去看ASP.NET MVC的源代码.所以,我想到如何在调试AS ...

  3. 常用的CSS Hack技术集锦

    来源:http://www.ido321.com/938.html 一.什么是CSS Hack? 不同的浏览器对CSS的解析结果是不同的,因此会导致相同的CSS输出的页面效果不同,这就需要CSS Ha ...

  4. bzoj 1097 [POI2007]旅游景点atr(最短路,状压DP)

    [题意] 给定一个n点m边的无向图,要求1开始n结束而且顺序经过k个点,给出经过关系x,y代表y必须在x之后经过,求最短路. [思路] 先对k个点进行spfa求出最短路. 设f[s][i]代表经过点集 ...

  5. Java ArrayList Sort

    Collections.sort(hits_list, new Comparator<ScoreDoc>(){ @Override public int compare(ScoreDoc ...

  6. 新建虚拟目录使用UNC共享文件夹(即:虚拟目录使用UNC共享文件夹)的方法 -摘自网络

    新建虚拟目录使用UNC共享文件夹(即:虚拟目录使用UNC共享文件夹)的方法1.UNC路径:\\192.168.1.2\test\,假设连接该UNC路径的用户名为:web,密码为:123 2.在原web ...

  7. 【转】Nginx系列(二)--模块化

    原博文出于: http://blog.csdn.net/liutengteng130/article/details/46700977  感谢! 高度模块化的设计设Nginx架构的基础.在Nginx中 ...

  8. URAL 2045 Richness of words (回文子串,贪心)

    Richness of words 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/J Description For each ...

  9. [C语言 - 3] 字符串

    字符数组 char * 看做一个特殊的字符数组, 在字符串结束为止添加'\0'结束符 (ASCII码0), 没有\0结尾的是普通的字符数组. 使用双引号定义的字符串自动在尾部加上\0 puts(s)函 ...

  10. uva 1356 Bridge ( 辛普森积分 )

    uva 1356 Bridge ( 辛普森积分 ) 不要问我辛普森怎么来的,其实我也不知道... #include<stdio.h> #include<math.h> #inc ...