【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 ...
 
随机推荐
- 【Java基础】继承中的代码块和构造方法的执行顺序探索
			
本文讲述有关一个类的静态代码块,构造代码块,构造方法的执行流程问题.首先来看一个例子 /** * Created by lili on 15/10/19. */ class Person{ stati ...
 - CF_216_Div_2
			
比赛链接:http://codeforces.com/contest/369 369C - Valera and Elections: 这是一个树上问题,用深搜,最开始贪心想得是只加叶子节点,找到一个 ...
 - Spring Framework 5.0.0.M3中文文档 翻译记录 introduction
			
翻译自: http://docs.spring.io/spring/docs/5.0.0.M3/spring-framework-reference/htmlsingle/#spring.tld.ha ...
 - MVC模式网站编写经验总结
			
单个网站使用MVC架构模式经验总结,包含具体网站包分类.包内类的编写.注意事项等方面.本人认为,按照如下包分类及编写方法,已经满足一个简单普通网站(主要针对java)的编写需求. MVC主要层级 数据 ...
 - html传參中?和&
			
<a href="MealServlet?type=findbyid&mid=<%=m1.getMealId()%> 在这句传參中?之后的代表要传递的參数当中有两个 ...
 - HDU4619+匈牙利
			
/* 匈牙利算法 二分匹配 最小点覆盖=最大匹配. 即踢掉最小点覆盖 */ #include<stdio.h> #include<string.h> #include<s ...
 - 结构体数组(C++)
			
1.定义结构体数组 和定义结构体变量类似,定义结构体数组时只需声明其为数组即可.如: struct Student{ int num; char name[20]; char sex[5]; int ...
 - windows API 实现截图
			
參考:http://bbs.csdn.net/topics/330154355 #include "stdio.h" #include "windows.h" ...
 - c#问答篇:对象与引用变量-----初学者的困惑
			
转自:http://www.cnblogs.com/huangyu/archive/2004/08/02/29622.html 从宏观的角度来看,对象是类的实例.比如: //定义一个名为Someone ...
 - 用sp_addlinkedserver建立链接服务器(sql server2008中通过测试)
			
--在SQL SERVER 2008里,可以按以下的方式建立链接服务器 ? EXEC sp_addlinkedserver @server='Test',--这里是给链接服务器取的 ...