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. IronPython .NET Integration官方文档翻译笔记

    http://ironpython.net/documentation/dotnet/这是原文地址 以下笔记仅记录阅读过程中我认为有必要记录的内容,大多数都是依赖翻译软件的机翻,配合个人对代码的理解写 ...

  2. Linux环境下安装Redis步骤即问题解决

    第一步:将安装包在window平台上解压后拷贝到Linux机器的/usr/soft目录下,并且为文件夹和文件赋予最高权限,chmod+x *: 第二步:进入到redis-3.2.6目录下,执行make ...

  3. 安装windows后grub的恢复

    问题: 原本是:双系统(linux和windows),后来换windows版本覆盖了grub2 解决方法: 进入windows后下载并安装EasyBCD并添加grub2的选项,重启看见了熟悉的启动项, ...

  4. CentOS 7安装nginx

    CentOS 7安装nginx 参考网上其他文章做的 安装Nginx 我们从nginx官方的RPM源来安装一个预构建的稳定版本的nginx包. rpm --import http://nginx.or ...

  5. kafka服务安装-SuSE Linux Enterprise Server 11 SP3

    kafka是一款分布式消息发布和订阅的系统,具有高性能和高吞吐率. 更多说明请自行了解,直接进入主题. kakfa 安装之前需要安装jdk,不做更多说明 一.下载kafka  进入下载页面:http: ...

  6. win8及win8.1商店出现0X80073CF9的解决办法!

    //添加appinstallagent无效的方法 http://jingyan.baidu.com/article/e52e3615a2b38f40c60c51d3.html

  7. C# typeof() 和 GetType()区别

    1.typeof(x)中的x,必须是具体的类名.类型名称等,不可以是变量名称. 2.GetType()方法继承自Object,所以C#中任何对象都具有GetType()方法,它的作用和typeof() ...

  8. Webupload + MVC 之上传下载

    最近工作中用到了 MVC 的上传及下载 , 写下感受 本项目中用到的是百度的webuploader <!--引入Jquery--> <script src="~/Conte ...

  9. CSS3 六边形绘制

    把一个104px的div放在它们之间,设置一个背景颜色: width: 0; border-bottom: 30px solid #6C6; border-left: 52px solid trans ...

  10. Foxit Reader(福昕PDF阅读器) v4.3.1.218 绿色专业版

    软件名称:Foxit Reader(福昕PDF阅读器) v4.3.1.218 绿色专业版 软件语言: 简体中文 授权方式: 免费软件 运行环境: Win 32位/64位 软件大小: 4.40MB 图片 ...