Codeforces Round #280 (Div. 2)E Vanya and Field(简单题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
本场题目都比较简单,故只写了E题。
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.
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.
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.
5 5 2 3
0 0
1 2
1 3
2 4
3 1
1 3
2 3 1 1
0 0
0 1
1 1
0 0
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(简单题)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- jquery.BannerRotator.js
项目地址:https://github.com/snipertulip/BannerRotator 演示地址:http://snipertulip.github.io/BannerRotator/de ...
- sql 字段先计算后再拿比对的字段进行比对 效率提升100倍
关于日期索引的使用,不要计算后再对比,否则使用不了索引例如:以下执行不了索引,耗时很大 dywl=# explain analyze SELECT car_bill.billno,car_bill.b ...
- a标签href不跳转 禁止跳转
a标签href不跳转 禁止跳转 当页面中a标签不需要任何跳转时,从原理上来讲,可分如下两种方法: 标签属性href,使其指向空或不返回任何内容.如: <a href="javascri ...
- Yoga安装Ubuntu后,wifi和亮度调节问题
http://askubuntu.com/questions/318608/lenovo-yoga-13-realtek-wireless-driver/358479#358479 http://it ...
- DJANGO学习一则
这个WEB框架,可以好好研究,相信很快就会用在工作上的. 相关文件: settings.py """ Django settings for djangoweb proj ...
- BZOJ 1497 最大获利(最大权闭合子图)
http://www.lydsy.com/JudgeOnline/problem.php?id=1497 思路:由题意可以得知,每个顾客都依赖2个中转站,那么让中转站连有向边到汇点,流量为它的建设费用 ...
- C51单片机内存优化
52本身有256B的数据存储区,如果没在意一些细节,很容易出现RAM超过128就报错的情况.现讲其问题解释如下: 最常见的是以下两种: ① 超过变量128后必须使用compact模式编译,实际的情况是 ...
- qt info.plist 添加
http://www.waitingfy.com/archives/1242 http://www.sollyu.com/settings-icon-under-the-qt-mac-applicat ...
- QDataStream类参考(串行化数据,可设置低位高位,以及版本号),还有一个例子
QDataStream类提供了二进制数据到QIODevice的串行化. #include 所 有成员函数的列表. 公有成员 QDataStream () QDataStream ( QIODevice ...
- Spiral Matrix II 解答
Question Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral or ...