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的更多相关文章

  1. 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 ...

  2. cf492E Vanya and Field

    E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Codeforces Round #280 (Div. 2)E Vanya and Field(简单题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 本场题目都比较简单,故只写了E题. E. Vanya and Field Vany ...

  4. codeforces 492E. Vanya and Field(exgcd求逆元)

    题目链接:codeforces 492e vanya and field 留个扩展gcd求逆元的板子. 设i,j为每颗苹果树的位置,因为gcd(n,dx) = 1,gcd(n,dy) = 1,所以当走 ...

  5. 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 ...

  6. CodeForces 492E Vanya and Field (思维题)

    E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. Codeforces 492E Vanya and Field

    E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. 【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 ...

  9. 【cf492】E. Vanya and Field(拓展欧几里得)

    http://codeforces.com/contest/492/problem/E 一开始没时间想,,诶真是.. 挺水的一道题.. 将每个点的横坐标都转换成0,然后找纵坐标有多少即可..即解方程 ...

随机推荐

  1. 自定义session扫描器

    为何要自定义session扫描器 由于服务器来管理session的销毁不怎么靠谱,因此很多网站都会自己定义一个session扫描器来管理session的创建和销毁. 实现思路 首先,创建一个sessi ...

  2. 【.NET-EF】Entity Framework学习笔记2 - 增删改(没查询)

    学习描述:用EF就像是省略了做实体类和DAL类,感觉是很方便,废话不多说,直接写步骤: 1.创建EF的edmx文件 这个其实在笔记1已说过,不过有些细节也要说,所以再说一遍,这里使用的是EF 6.1版 ...

  3. PWA - 渐进式网络应用初认识

    Progressive Web Apps 简称PWA,是一种接近原生用户体验的渐进增强的web-app.从浏览器演进而来,沉浸式的体验,改进web的性能低下等.是Google 在2015年提出,今年才 ...

  4. liunx服务器常见监控指标

    1. CPU Utilization 英文翻译就是CPU的利用率75%以上就比较高了(也有说法是80%或者更高).有的博客上说除了这个指标外,还要结合Load Average和Context Swit ...

  5. 【1】Hover 效果收集

    各种 hover 效果  github repository>>  git 仓库 1. 背景图的 hover 效果 原页面>> githubSite>>

  6. xtrabackup 开启压缩备份

    完整备份innobackupex --defaults-file=/etc/my.cnf --host=localhost --user=bkpuser --password=s3cret /data ...

  7. sql 时间格式化

    sql server2000中使用convert来取得datetime数据类型样式(全) 日期数据格式的处理,两个示例: CONVERT(varchar(16), 时间一, 20) 结果:2007-0 ...

  8. asp.net——初识多线程

    1.首先讲解一下什么是线程(该定义是参考线程的百度百科) 线程,有时被称为轻量级进程(Lightweight Process,LWP),是程序执行流的最小单元.一个标准的线程由线程ID,当前指令指针( ...

  9. tar命令结合find搜索将指定条件的文件进行打包压缩

    今天处理 /tmp 临时目录下 session 文件过多的问题,顺便找到了这个 tar 结合 find 打包压缩的方法,记录下来,很实用的哈! 搜索 /tmp 目录下 创建超过 24 分钟的文件 fi ...

  10. SAP HANA 能做什么

    HANA不是一个数据仓库,而是一个平台,在这个平台之上用户可以构建数据仓库或集市.报表和仪表盘等. HANA能做的,首先是作为内存数据库,提供数据插入.修改和高效的查询功能. 其次,作为一个平台,在H ...