转载请注明出处: 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. RCP打包出来 运行 出现 JVM terminated.exit code = 13

    在建立PM.product,即打包时,没有添加相应的插件,导致无法运行

  2. 【2】最简单的Laravel5.1程序分析

    1.上图!说一下laravel的基本MVC(模型-控制器-视图)原理 2.具体分析 用户输入网址localhost:8888之后,首先请求发送到服务器的laravel应用的public目录下index ...

  3. php 对问卷结果进行统计

    背景: 由于具体工作的原因,我做了一份纸质的问卷调查表,调查表的主要内容是让用户对10项要求(编号为A,B....)进行优先级排序,所以我得到的结果是好几百份类似于A>I>H>G&g ...

  4. HTML中元素水平居中。

    一丶margin:0 auto; 试用最多的方法,简单实用. 二丶vertical-align:middle; 只适用于内嵌元素,比如说一个div中有一个图片和文字,要让图片和文字中线对齐. < ...

  5. 阅读书目_2014H1

    1.<程序员修炼之道 专业程序员必知的33个技巧>(完成) 注:更多是面向程序员全工作流程的. 2.linux shell脚本攻略 适合初学,但不方便作为参考手册查阅. 3.编写可读代码的 ...

  6. 单片微机原理P3:80C51外部拓展系统

    外部拓展其实是个相对来说很好玩的章节,可以真正开始用单片机写程序了,比较重要的是外部存储器拓展,81C55拓展,矩阵键盘,动态显示,DAC和ADC.   0. IO接口电路概念与存储器拓展 1. 为什 ...

  7. C语言读写伯克利DB 4

    因为缓存数据的buffer总是不够大(会引起段错误)索性从堆上拿了两块大内存 /* 功能说明:逐日存储来访用户(使用伯克利DB) 根据存储的用户信息确定某用户是否是首次来访用户(未被存储的伯克利DB) ...

  8. C语言复习--实现栈

    C #include <stdio.h> #include <stdlib.h> #define STACK_SIZE 100 typedef char TYPE; typed ...

  9. rlwrap 的安装使用

    rlwrap 的安装使用 在Windows操作系统上,当在DOS命令窗口中运行SQL*Plus的时候,可以使用向上,向下键来跳回之前已经执行过的SQL语句.你可以根据需要修改他们,然后按Enter键重 ...

  10. find之exec和args

    本来以为以前的差不多够用了.呵呵,看到很多高手用高技巧,心痒痒的觉得我自己还可以提升啊..哈哈哈. 这个实践起来之后,,SED,AWK也得深化一下,,,SHELL和PYTHON,作运维的两样都不能废. ...