Codeforces #280 Div.2 E.Vanya and Field 数学,数论
2016-08-01 16:59
399 查看
第一道完全没看题解直接出的E题……纪念一下记下来吧……
题意:n*n的矩阵,边际循环,每次可以从当前位置(x,y)走到((x+dx)%n,(y+dy)%n),保证gcd(n,dx)=1,gcd(n,dy)=1;
在矩阵中有些地方有果树,问从哪个位置开始走能够经过的果树最多;
题解:考虑能够从一棵果树走到另一棵,设这两个果树的坐标为(x1,y1),(x2,y2),那么我们可以得到
(x2-x1)/dx=(y2-y1)/dy (mod n)
两边乘以dx*dy,可以得到
(x2-x1)*dy=(y2-y1)*dx (mod n)
整理一下,
x1*dy-y1*dx=x2*dy-y2*dx (mod n)
所以只需要开一个map或者大小为n的数组,记录下每个果树的(x*dy-y*dx)%n值,在记录的时候如果比当前值大就更新答案就行了,代码非常短……
题意:n*n的矩阵,边际循环,每次可以从当前位置(x,y)走到((x+dx)%n,(y+dy)%n),保证gcd(n,dx)=1,gcd(n,dy)=1;
在矩阵中有些地方有果树,问从哪个位置开始走能够经过的果树最多;
题解:考虑能够从一棵果树走到另一棵,设这两个果树的坐标为(x1,y1),(x2,y2),那么我们可以得到
(x2-x1)/dx=(y2-y1)/dy (mod n)
两边乘以dx*dy,可以得到
(x2-x1)*dy=(y2-y1)*dx (mod n)
整理一下,
x1*dy-y1*dx=x2*dy-y2*dx (mod n)
所以只需要开一个map或者大小为n的数组,记录下每个果树的(x*dy-y*dx)%n值,在记录的时候如果比当前值大就更新答案就行了,代码非常短……
/*********************************************** Made by Euphoria. ************************************************/ #define _CRT_SECURE_NO_WARNINGS #include<cstdio> #include<cmath> #include<cstring> #include<cstdlib> #include<ctime> #include<cctype> #include<cassert> #include<iostream> #include<vector> #include<map> #include<queue> #include<string> #include<set> #include<algorithm> #include<stack> #include<list> //#pragma comment(linker, "/STACK:102400000,102400000") using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef unsigned int ui; typedef long double ld; #define mem(a,b) memset(a,b,sizeof(a)) #define INF 0x7fffffff #define xx first #define yy second #define PI acos(-1.0) #define eps 1e-8 #define MOD 1000000007 #define N 100001 map<ll, int>M; int main() { ll n, m, dx, dy; cin >> n >> m; cin >> dx >> dy; ll cnt = 0; pii ans; for (int i = 1; i <= m; i++) { ll a, b; cin >> a >> b; ll tmp = ((a * dy - b * dx) % n + n) % n; M[tmp]++; if (cnt < M[tmp] ) { cnt = M[tmp]; ans.xx = a; ans.yy = b; } } cout << ans.xx << ' ' << ans.yy << endl; }
相关文章推荐
- Codeforces Round #280 (Div. 2) E. Vanya and Field (数学GCD)
- CodeForces #280 E Vanya and Field
- Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 数学+预处理
- Codeforces Round 280 Div2 B Vanya and Lanterns(binary serch)
- Codeforces Round #280 (Div. 2) C. Vanya and Exams 贪心
- Codeforces Round #410 (Div.2) C.Mike and gcd problem-数学
- codeforces B. Ralph And His Magic Field 数学题+快速幂
- Codeforces Round #280 (Div. 2) C. Vanya and Exams 贪心
- Codeforces Round #280 (Div. 2)A. Vanya and Cubes(简单计算)
- Codeforces Round #272 (Div. 2) C. Dreamoon and Sums (数学 思维)
- Codeforces Round 261 Div.2 E Pashmak and Graph --DAG上的DP
- Codeforces Round #293 (Div. 2) C. Anya and Smartphone 数学题
- Levko and Permutation CodeForces - 361B 思维 数论
- Codeforces Round 389 Div.2 B. Santa Claus and Keyboard Check(模拟)
- Codeforces Round 261 Div.2 D Pashmak and Parmida&#39;s problem --树状数组
- Codeforces Round #190 DIV.2 A. Ciel and Dancing
- Codeforces Round #174 (Div. 2) Cows and Primitive Roots(数论)
- Codeforces Round 389 Div.2 B. Santa Claus and Keyboard Check(模拟)
- Codeforces Vanya and Cubes
- Codeforces Round #285 (Div. 1)B. Misha and Permutations Summation(数学+数据结构打脸)