Codeforces #280 Div.2 E.Vanya and Field 数学,数论
来源:互联网 发布:产品标贴制作软件 编辑:程序博客网 时间:2024/04/30 09:07
第一道完全没看题解直接出的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值,在记录的时候如果比当前值大就更新答案就行了,代码非常短……
/***********************************************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 100001map<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;}
0 0
- Codeforces #280 Div.2 E.Vanya and Field 数学,数论
- cf Round #280 (Div. 2) E. Vanya and Field 数学
- Codeforces Round #280 (Div. 2) E. Vanya and Field (数学GCD)
- Codeforces Round #280 (Div. 2) E. Vanya and Field
- CodeForces #280 E Vanya and Field
- CodeForces 492E Vanya and Field
- Codeforces Round #447 (Div. 2) B. Ralph And His Magic Field(数论,组合数学)
- E. Vanya and Brackets(Codeforces Round #308 (Div. 2))
- Codeforces Round #308 (Div. 2) E. Vanya and Brackets
- Codeforces Round #355 (Div. 2)E. Vanya and Balloons
- Codeforces 492E Vanya and Field 规律题
- Codeforces 492E Vanya and Field(拓展欧几里得)
- Codeforces 492E Vanya and Field 题解&代码
- CodeForces-492E Vanya and Field(思维题/最小公倍数)
- CodeForces 492E Vanya and Field(拓展欧几里得)
- Codeforces Round #395 (Div. 2)E: Timofey and remoduling(数学+数论)
- Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 数学+预处理
- Codeforces #280 (Div. 2)D Vanya and Computer Game
- CocosCreator自定义事件总结
- jsp分页显示的代码与详细步骤 复制代码
- 扫雷App的实现
- spoj 687 repeats
- android 6.0的权限问题
- Codeforces #280 Div.2 E.Vanya and Field 数学,数论
- Android扫描枪(PDA)开发
- 心血来潮,小试c++11
- rf中对于有滚动条的页面中元素的处理
- POJ 3278 抓牛简单广搜
- 个人总结——studio的常用插件的使用(工作实践)
- 基于QT实现对网络摄像头数据的显示
- 深入理解HashMap(及hash函数的真正巧妙之处)
- Cloudera Manager 5安装