【CF492E】【数学】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.
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.
0 0
1 2
1 3
2 4
3 1
1
2
3
4
5
6
|
5 5 2 3
0 0
1 2
1 3
2 4
3 1
|
1
|
1 3
|
0 0
0 1
1 1
1
2
3
4
|
2 3 1 1
0 0
0 1
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棵给定坐标的苹果树,选定一个起点(x, y),每次以横坐标+dx(mod n),纵坐标 +dy(mod n)的形式进行移动,其中gcd(dx, n) = gcd(dy, n) = 1,询问选择哪个起点能经过最多的苹果树?
因为有gcd(dx, n) = gcd(dy, n) = 1 所以可以得知行走的路线一定是一个循环,并且循环的长度为n,且能够经过每一个x坐标和每一个y坐标。
我们不妨将起点设在x为0的位置,然后预处理出到其他的x坐标所需要变化的y值,然后就可以将苹果树进行"平移"到x坐标为0上,然后就可以做了。
【CF492E】【数学】Vanya and Field的更多相关文章
- 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 ...
- cf492E 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(简单题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 本场题目都比较简单,故只写了E题. E. Vanya and Field Vany ...
- Vanya and Field
Vanya and Field 题目链接:http://www.codeforces.com/problemset/problem/492/E 逆元 刚看到这题的时候一脸懵逼不知道从哪下手好,于是打表 ...
- codeforces 492E. Vanya and Field(exgcd求逆元)
题目链接:codeforces 492e vanya and field 留个扩展gcd求逆元的板子. 设i,j为每颗苹果树的位置,因为gcd(n,dx) = 1,gcd(n,dy) = 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 ...
- CodeForces 492E Vanya and Field (思维题)
E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 492E Vanya and Field
E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- cf492E. Vanya and Field(扩展欧几里得)
题意 $n \times n$的网格,有$m$个苹果树,选择一个点出发,每次增加一个偏移量$(dx, dy)$,最大化经过的苹果树的数量 Sol 上面那个互素一开始没看见,然后就GG了 很显然,若$n ...
随机推荐
- Headless MSBuild Support for SSDT (*.sqlproj) Projects [利用msbuild自动化部署 .sqlproj]- 摘自网络
Update: breaking change: http://sqlproj.com/index.php/2012/10/dacfx-sept-2012-updates-break-headless ...
- 问题-[Delphi]PixelFormat 图像颜色的数据格式
PixelFormat: (指定图像中每个像素的颜色数据的格式) Delphi 微软 ...
- 引入less报错解决方法以及浏览器设计不同的地方
XMLHttpRequest cannot load file:///C:/Users/PAXST/Desktop/805/first.less. Cross origin requests are ...
- java利用Google Zxing实现 二维码生成与解析
1.引入zxing 2.使用下面两个类:QRCodeUtil.java和BufferedImageLuminanceSource.java 3.新建单元测试类 复制下面测试代码即可. 1.pom文件中 ...
- C#基础知识学习手记1
这篇随笔主要用来记录我在C#学习过程做的笔记,算作是一门课程中的小知识点吧. 1. 变量和表达式 1.1 如何在输出带有引号(英文双引号.英文单引号)以 ...
- PHP操作SQLITE
一直以来.我们操作SQLITE,都是基于PHP默认的SQLITE操作模块. 今天介绍一个能够操作SQLITE2,和SQLITE3的PHP类,此为我封装的. <? php abstract cla ...
- C#泛型对类型参数的推断
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- flash解析json格式
flash对于json格式的解析在Flash CS6的版本对于json格式的数据提供了支持,用以下方式即可以进行转换: var persons = JSON.parse('[{"name&q ...
- 解决PL/SQL Developer中文乱码的问题
set nls_lang=SIMPLIFIED CHINESE_CHINA.ZHS16GBK cd "c:\Program Files\PLSQL Developer" PLSQL ...
- 重写equals方法的约定
1. 什么时候需要重写Object.equals方法 如果类具有自己特有的“逻辑相等”概念(不同于对象等同的概念),而且超类还没有覆盖equals以实现期望的行为,这时我们就需要覆盖equals方法. ...