转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud

本场题目都比较简单,故只写了E题。

E. Vanya and Field

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 test(s)
input
5 5 2 3
0 0
1 2
1 3
2 4
3 1
output
1 3
input
2 3 1 1
0 0
0 1
1 1
output
0 0
Note

In the first sample Vanya's path will look like: (1, 3) - (3, 1) - (0, 4) - (2, 2) - (4, 0) - (1, 3)

In the second sample: (0, 0) - (1, 1) - (0, 0)


题意:在一个n*n的方阵内,有m棵果树,在选取一个点之后,每次只能以向量(dx,dy)方向前进。问选取哪个点可以经过最多的的果树,只要输出一个点的坐标即可。

分析:由于gcd(n,dx)=gcd(n,dy)=1,所以,在n次之后一定会回到原点。同时,每个x坐标都只经过一次,每个y坐标都只经过一次。

那么,通过O(n)的预处理,我们可以得出对于任意一个y坐标从y坐标为0的点开始,需要经过多少次的移动才能够得到该y坐标。

那么在后面的m棵果树,我们可以O(1)得知该果树所对应的y坐标为0的起点,到该点所需要的步数,接下来,只需要减去相应的x坐标即可得到对应的y坐标为0的点。

 //gaoshenbaoyou  ------ pass system test
#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype>
using namespace std;
#define XINF INT_MAX
#define INF 0x3FFFFFFF
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<int> VI;
const int maxn=;
int num[maxn];
int d[maxn];
int main()
{
ios::sync_with_stdio(false);
int n,m,dx,dy;
cin>>n>>m>>dx>>dy;
int y=;
for(int i=;i<n;i++)
{
d[y]=i;
y+=dy;
y%=n;
}
long long tx,ty;
int ansx,ans=;
for(int i=;i<m;i++)
{
cin>>tx>>ty;
long long t=d[ty];
t=(tx+(n-t)*dx)%n;
num[t]++;
if(num[t]>ans)
{
ans=num[t];
ansx=t;
}
}
cout<<ansx<<" "<<<<endl;
return ;
}

代码君

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

  1. 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 ...

  2. Codeforces Round #280 (Div. 2) E. Vanya and Field 数学

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

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  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) D. Vanya and Triangles 水题

    D. Vanya and Triangles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55 ...

随机推荐

  1. Java系列--第二篇 基于Maven的Android开发HelloAndroidWorld

    曾经写过一篇Android环境配置的随笔,个人感觉特繁琐,既然有Maven,何不尝试用用Maven呢,经网上搜索这篇文章但不限于这些,而做了一个基于Maven的Android版的Hello Andro ...

  2. Form 表单常用正则验证 (收藏)

    1.^\d+$ //匹配非负整数(正整数 + 0) 2.^[0-9]*[1-9][0-9]*$ //匹配正整数 3.^((-\d+)|(0+))$ //匹配非正整数(负整数 + 0) 4.^-[0-9 ...

  3. 织梦dedecms返回上一级链接代码

    如题:织梦dede手机页面,如果我进入了下一级页面,想回上一级,<a href="xx">该用什么标签? 用JS实现,代码如下 <a href="jav ...

  4. web.config 拆分

    <appSettings configSource="xxx.config"> </appSettings> 在 web.config 加入上面  然后创建 ...

  5. lnmp 60秒的服务器缓存时间

    1.问题 php代码写好之后执行发现居然没有生效,打断点,改代码.刷新都没有达到预期的效果.但是间隔60秒之后刷新就看到效果了,或者删除文件就里面见效. 2.原因 从phpinfo()页面输出搜索&q ...

  6. 再谈Redirect(客户端重定向)和Dispatch(服务器端重定向)

    这是两个常常被放在一起进行比较的概念,今天对这两个概念再重新回顾一下,前者发生在客户端(浏览器),后者发生在服务器端,因此也有人把前者称为客户端重定向,把后者称为服务器端重定向,虽然对于后者这种称谓并 ...

  7. [bzoj 1001][Beijing2006]狼抓兔子 (最小割+对偶图+最短路)

    Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的, 而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一 ...

  8. android 显示特殊符号

    http://hsx9566.iteye.com/blog/1305052 在android上使用ASCII显示特殊符号 在xml中表示如下: <string name="symbol ...

  9. VS代码生成工具ReSharper使用手册:配置快捷键

    原文 http://www.cnblogs.com/PHPIDE/archive/2013/05/16/3081783.html VS代码生成工具ReSharper提供了丰富的快捷键,可以极大地提高你 ...

  10. Mac OS X Mavericks使用手册

    基本信息 作者: 施威铭研究室 出版社:清华大学出版社 ISBN:9787302386018 上架时间:2014-12-30 出版日期:2015 年1月 开本:16 版次:1-1 所属分类: 计算机 ...