Codeforces 492E Vanya and Field
2 seconds
256 megabytes
standard input
standard output
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)
题目给出 gcd( n , dx ) = gcd( n , dy ) = 1 , 意味着(0~n-1)每个数都可以遍历到。
然后从x,y轴方向0坐标开始分别预处理出的n个数。
对于两颗苹果树,如果他们 y坐标到0坐标的距离 与 x坐标到0坐标的距离 两者的差值相同。
那么这两个坐标是来自同一个环的。
扫一遍m个点以后取出最大的就可以了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <algorithm> using namespace std;
typedef long long LL;
typedef pair<LL,int> pii;
const int N = ;
const int M = ;
const int inf = 1e9+;
#define X first
#define Y second int n , m , dx , dy , x[N] , y[N] , cnt[N] , id ;
vector<pii>e;
void test() {
for( int i = ; i < n ; ++i ) cout << x[i] << ' ' ; cout <<endl ;
for( int i = ; i < n ; ++i ) cout << y[i] << ' ' ; cout <<endl ;
}
void Run() { memset( cnt , , sizeof cnt ) ;
x[] = ; id = ; for( int i = dx ; i != ; i = (i+dx)%n ) x[i] = id++;
y[] = ; id = ; for( int i = dy ; i != ; i = (i+dy)%n ) y[i] = id++;
// test();
e.resize(m);
for( int i = ; i < m ; ++i ) {
cin >> e[i].X >> e[i].Y ;
int disx = ( x[e[i].X] + n ) % n ;
int disy = ( y[e[i].Y] + n ) % n ;
cnt[ (disx + n - disy)%n ] ++ ;
}
LL ans = ;
for( int i = ; i < n ; ++i ) {
if( cnt[ans] < cnt[i] ) ans = i;
}
cout << ( ans*dx ) % n << ""<< endl ;
}
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
ios::sync_with_stdio(false);
while( cin >> n >> m >> dx >> dy ) Run();
}
Codeforces 492E Vanya and Field的更多相关文章
- codeforces 492E. Vanya and Field(exgcd求逆元)
题目链接:codeforces 492e vanya and field 留个扩展gcd求逆元的板子. 设i,j为每颗苹果树的位置,因为gcd(n,dx) = 1,gcd(n,dy) = 1,所以当走 ...
- CodeForces 492E 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)E Vanya and Field(简单题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 本场题目都比较简单,故只写了E题. E. Vanya and Field Vany ...
- 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 ...
- Vanya and Field
Vanya and Field 题目链接:http://www.codeforces.com/problemset/problem/492/E 逆元 刚看到这题的时候一脸懵逼不知道从哪下手好,于是打表 ...
- cf492E Vanya and Field
E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 677D Vanya and Treasure 暴力+BFS
链接 Codeforces 677D Vanya and Treasure 题意 n*m中有p个type,经过了任意一个 type=i 的各自才能打开 type=i+1 的钥匙,最初有type=1的钥 ...
- 【cf492】E. Vanya and Field(拓展欧几里得)
http://codeforces.com/contest/492/problem/E 一开始没时间想,,诶真是.. 挺水的一道题.. 将每个点的横坐标都转换成0,然后找纵坐标有多少即可..即解方程 ...
随机推荐
- 汇编语言之寄存器使用bx si di bp
转载自:https://www.cnblogs.com/youxin/archive/2012/05/29/2524780.html 如果你看到这篇博客时正在做第七章问题,强烈建议先去把8.1~8.4 ...
- 关于微信小程序的一些总结
mpvue? {{}} 在vue和小程序中的区别? 01 小程序中{{}}和vue中的{{}}用法基本一致,可以显示data中的数据,可以写表达式 不一样的地方? 01 小程序的{{}}可以写在属性中 ...
- .ef core 多对对关系的关联方法
最近在用.net core 重构博客,在使用ef core连表查询时,遇到了一些问题.记录一下. 关系:一个博客可以有多个标签,一个标签可以属于多个博客,博客和标签之间存在多对多的关系 下面是实体代码 ...
- shell --08 例子
目录 1.按照时间生成文件2018-05-22.log将每天的磁盘使用状态写入到对应日期的文件 [root@web01 ceshi]# cat 1.sh #!/bin/bash Date=`date ...
- mongodb使用简介
mongodb简介 在使用nodejs时候,需要存储一些简单json数据的情况下,很多人会推荐使用mongodb.mongodb是一个文档型数据库,在 sql 中,数据层级是:数据库(db) -> ...
- 1.VUE前端框架学习记录一
VUE前端框架学习记录一文字信息没办法描述清楚,主要看编码实战里面,有附带有一个完整可用的Html页面,有需要的同学到脑图里面自取.脑图地址http://naotu.baidu.com/file/f0 ...
- 【挖坟】HDU3205 Factorization
分圆多项式 问题在于精度貌似出了一些奇怪的问题... [输出也写的有问题QAQ] 完全不会处理了 加上全网没有题解T^T 挖个坑以后补.. #include<cstdio> #includ ...
- BZOJ3926 诸神眷顾的幻想乡
传送门 树上SAM! 显然如果树上一条一条字符串放的话那么是n^2的w 但是 题目的性质非常吼啊! 20个叶子节点 我们就可以 把所有叶子结点拎出来当根 全部扔到一个SAM里 就吼啦 最后的答案是 ...
- 人生苦短_我用Python_类与对象的概念_006
Python类与对象的概念类和对象--->万事万物都对象物以类聚.人以群分 --->?划分标准性别分 男女 中性成绩分 优秀 良好 不及格 类->根据类的属性来划分类的实例-> ...
- 如何在Ubuntu下搭建tftp服务器
远程桌面连接工具 今天开始调试arm的板子,要通过tftp下载到板子上,所以又要配置tftp服务器,真的烦死了… (本人酷爱装系统,所以经常都要搞配置) 因为之前已经在Ubuntu下搭建过很多次t ...