Vanya and Field
Vanya and Field
题目链接:http://www.codeforces.com/problemset/problem/492/E
逆元
刚看到这题的时候一脸懵逼不知道从哪下手好,于是打表找规律。但是打出来的东西完全不能看啊,有个鬼规律(╯‵□′)╯︵┻━┻,是我数据处理不当?按x排序后发现从一个点出发可以到达任意一个x坐标,回过去看题,发现有这么一句话:The following condition is satisfied for the vector:$gcd(n,dx)=gcd(n,dy)=1$,恩,好像有点思路了。(x,y)的下一个点的坐标是[(x+k*dx)%n,(y+k*dy)%n]也可以写作[(x+k*dx+a*n),(y+k*dy+b*n)],也就是说每个不互相覆盖的(x,y)都唯一对应一个(0,y'),利用扩展欧几里得(如果n是质数可以用费马小定理)计算dx对n的逆元,从而可以求得对应的y'。于是只要处理每个(x,y),对应的(0,y')个数++,最后找到个数最多的(0,y')就好了。
代码如下:
#include<cstdio>
#define LL long long
using namespace std;
LL k,t;
struct node{
LL sum,x,y;
bool flag;
}times[];
LL query[][];
LL n,m,dx,dy;
LL exGCD(LL a,LL b){
if(b==){
k=;
t=;
return a;
}
LL r=exGCD(b,a%b);
LL tmp=k;
k=t;
t=tmp-(a/b)*t;
return r;
}
int main(void){
LL Max=,Index=;
scanf("%I64d%I64d%I64d%I64d",&n,&m,&dx,&dy);
exGCD(dx,n);
k=(k%n+n)%n;
for(LL i=;i<m;++i){
LL x,y;
scanf("%I64d%I64d",&x,&y);
query[i][]=x,query[i][]=y;
LL temp=y-x*k*dy;
temp = (temp%n + n)%n;
temp%=n;
times[temp].sum++;
if(times[temp].sum>Max){
Max=times[temp].sum;
Index=temp;
}
if(times[temp].flag==){
times[temp].x=x;
times[temp].y=y;
times[temp].flag=;
}
}
printf("%I64d %I64d\n",times[Index].x,times[Index].y);
return ;
}
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 ...
- 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
Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th a ...
- 【cf492】E. Vanya and Field(拓展欧几里得)
http://codeforces.com/contest/492/problem/E 一开始没时间想,,诶真是.. 挺水的一道题.. 将每个点的横坐标都转换成0,然后找纵坐标有多少即可..即解方程 ...
随机推荐
- selenium自动化过程中遇到的小问题(未完待续)
1.chrome浏览器调用不起来 代码没出错的情况下,检查下chrome浏览器的版本与chromedriver.exe的版本是否匹配;下面的表格是根据网上及官网整理的chromedriver与chro ...
- Docker集群实验环境布署--swarm【3 注册服务监控与自动发现组件--consul】
参考官网集群配置方式 https://hub.docker.com/r/progrium/consul/ 集群中需要manager与node能通信consul的发现服务,不然,管理节点选举不了,无 ...
- redis中的set集合问题
转自:http://www.linuxidc.com/Linux/2014-12/111015.htm Redis数据库(set类型和zset类型) [日期:2014-12-30] 来源:Linux社 ...
- mysql数据库主从搭建
一.最近一直在学习mysql的东西,刚好看到mysql如何搭建主从数据库,搜集了很多资料后大致了解了mysql主从复置的原理.以下是我的理解: 举例master为主数据库,slave为从数据库. sl ...
- 目标检测中proposal的意义
在目标检测中,从很早就有候选区域的说法,也是在2008年可能就有人使用这个方法,在2014年的卷积神经网络解决目标检测问题的文章中,这个候选框方法大放异彩,先前的目标检测方法主要集中在使用滑动窗口的方 ...
- 对于行高(line-height)的一些理解
刚一开始学习这个特性的时候,总是出一些当时看起来很奇怪的问题.现在决定重新整理一下.毕竟使用css,十行揉在一起凑出效果是一种使用,知道为什么会有这种效果也是一种使用.我们需要做一些测试,所以首先需要 ...
- Batch File Rename Utility(文件批量改名软件) 1.1.4231
软件名称: Batch File Rename Utility(文件批量改名软件) 1.1.4231.23098 软件语言: 英文 授权方式: 免费软件 运行环境: Win7 / Vista / Wi ...
- apache 配置静态文件缓存和开启gzip压缩
1,设置文件静态缓存3天: 在httpd.conf 里添加如下代码: #文件静态缓存配置 <IfModule expires_module> #打开缓存 ExpiresActive on ...
- PL SQL Developer报错框乱码
在系统变量里设置 变量名:NLS_LANG 变量值设为:SIMPLIFIED CHINESE_CHINA.ZHS16GBK
- ios GCD的使用及封装
实现代码: CGDHelper /* * Grand Central Dispatch (GCD)是Apple开发的一个多核编程的解决方法. * 系统要求:iOS4.0以上. */ #import & ...