转载请注明出处: 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. Linux Shell 中的反引号,单引号,双引号

    反引号在 (`) 键盘的Tab键的上方.1键的左方.在Linux中起着命令替换的作用.命令替换是指shell能够将一个命令的标准输出插在一个命令行中任何位置.如下,shell会执行反引号中的date命 ...

  2. include 和 require 的区别

    1. 首先不去介绍大家都知道的区别,百度上都进行了详细的说明,对于返回值的方面大家都很少提到. include 和 require 还有一个区别就是是否具有返回值.参见手册 对include 加载文件 ...

  3. SQL中什么叫模式

    模式(schema) 是 数据库体系结构中的一个节点对于 SQL Server 数据库来说.访问具体的一个表,可以由 4个部分组成分别为 服务器名, 数据库名,模式名,表名.对于访问本地的数据库因为 ...

  4. c# 大量拼接xml时内存溢出解决方法

    public static string SelectUNnormalPriceSTrans(EUNnormalPriceS rqInfo) { string guidStrJianJclFirst ...

  5. win7 下的open live writer代码插件

    open live writer 是博客园官方推荐的编辑器.恰好被它的各种便利吸引住了,于是花点时间研究一下,结果又用了好长时间,因为代码插件一时安装不了.在这里推荐小伙伴们可以先去看看这篇博文:ht ...

  6. SVN上传代码时代码失败

    Description : You are not authorized to access the files in the repository.Suggestion : You might be ...

  7. ubuntu install express

    1:全局安装express 2:查看Express安装的版本信息 3:运行express 创建工程,提示express未安装 4:重新安装Express4,这次安装成功 5:使用Express构建项目 ...

  8. iPhone 和Android应用,特殊的链接:打电话,短信,email;

    http://ice-k.iteye.com/blog/1426526 下面的这篇文章主要是说,网页中的链接如何写,可以激活电话的功能. 例如,页面中展示的是一个电话号码,当用户在手机浏览器里面点击这 ...

  9. 【转】Linux中变量$#,$@,$0,$1,$2,$*,$$,$?的含义

    原文网址:http://dadekey.blog.51cto.com/107327/119938 我们先写一个简单的脚本,执行以后再解释各个变量的意义   # touch variable # vi ...

  10. jquery使用总结

    jquery使用总结-常用DOM操作 (1)查询或设置元素属性操作 html()   //获取匹配元素集合中的第1个元素 html(htmlString)  //为匹配集合中的所有元素设置内容 tex ...