Codeforces 724C Ray Tracing 扩展欧几里得
吐槽:在比赛的时候,压根就没想到这题还可以对称;
题解:http://blog.csdn.net/danliwoo/article/details/52761839
比较详细;
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<ctime>
#include<cmath>
#define LL long long
using namespace std;
#define LL long long
#define up(i,j,n) for(int i=(j);(i)<=(n);(i)++)
#define max(x,y) ((x)<(y)?(y):(x))
#define min(x,y) ((x)<(y)?(x):(y))
#define FILE "1"
const int maxn=;
const LL inf=10000000000000LL;
int n,m,k;
void init(){
scanf("%d%d%d",&n,&m,&k);
}
void gcd(LL a,LL b,LL &d,LL &x,LL &y){
if(b==){d=a;x=;y=;return;}
gcd(b,a%b,d,x,y);
int t=x;
x=y;
y=t-a/b*x;
return;
}
LL t(LL a,LL b,LL c,LL &x,LL &y ){
LL d;gcd(a,b,d,x,y);
if(c%d)return -;
LL ran=b/d;if(ran<)ran=-ran;
x*=c/d;
x=(x%ran+ran)%ran;
return ;
}
LL get(LL x,LL y,LL maxx){
LL K,S;
if(t(*n,-*m,y-x,K,S)==-)return maxx+;
LL ans=*K*n+x;
if(ans<||ans>maxx)return maxx+;
return ans;
}
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL work(LL x,LL y){
LL maxx=1LL*n/gcd(n,m)*m;
LL minn=maxx+;
minn=min(get(x,y,maxx),minn);
minn=min(get(-x,y,maxx),minn);
minn=min(get(x,-y,maxx),minn);
minn=min(get(-x,-y,maxx),minn);
if(minn==maxx+)return -;
else return minn;
}
void slove(){
init();
up(i,,k){
LL x,y;
scanf("%I64d%I64d",&x,&y);
printf("%I64d\n",work(x,y));
}
}
int main(){
slove();
}
Codeforces 724C Ray Tracing 扩展欧几里得的更多相关文章
- CF724C Ray Tracing 扩展欧几里得 平面展开
LINK:Ray Tracing 虚这道题很久了 模拟赛考了一个加强版的 瞬间就想到了这道简化版的. 考虑做法 暴力模拟可能可以 官方正解好像就是这个. 不过遇到这种平面问题可以考虑把平面给无限的展开 ...
- codeforces 1244C (思维 or 扩展欧几里得)
(点击此处查看原题) 题意分析 已知 n , p , w, d ,求x , y, z的值 ,他们的关系为: x + y + z = n x * w + y * d = p 思维法 当 y < w ...
- CodeForces 724C Ray Tracing(碰撞类,扩展gcd)
又一次遇到了碰撞类的题目,还是扩展gcd和同余模方程.上次博客的链接在这:http://www.cnblogs.com/zzyDS/p/5874440.html. 现在干脆解同余模直接按照套路来吧,如 ...
- codeforces 724c Ray Tracing
好题 原题: There are k sensors located in the rectangular room of size n × m meters. The i-th sensor is ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C.Ray Tracing (模拟或扩展欧几里得)
http://codeforces.com/contest/724/problem/C 题目大意: 在一个n*m的盒子里,从(0,0)射出一条每秒位移为(1,1)的射线,遵从反射定律,给出k个点,求射 ...
- C. Ray Tracing——披着搜索外衣的扩展欧几里得
[题目大意] 给你一个n*m的矩形,光线从(0,0)出发,沿右上方向以每秒根号2米的速度运动,碰到矩形边界就会反弹(符合物理规律的反弹),询问k个点,这些点都在矩形内部且不在矩形边界上,求光经过这些点 ...
- 【扩展欧几里得】BAPC2014 I Interesting Integers (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- 【数论】【扩展欧几里得】Codeforces 710D Two Arithmetic Progressions
题目链接: http://codeforces.com/problemset/problem/710/D 题目大意: 两个等差数列a1x+b1和a2x+b2,求L到R区间内重叠的点有几个. 0 < ...
- [codeforces 200 E Tractor College]枚举,扩展欧几里得,三分
题目出自 Codeforces Round #126 (Div. 2) 的E. 题意大致如下:给定a,b,c,s,求三个非负整数x,y,z,满足0<=x<=y<=z,ax+by+cz ...
随机推荐
- Java 异常处理的优劣
Java编程中的异常处理是一个很常见的话题了,几乎任何一门介绍性的Java课程都会提到异常处理.不过,我认为很多人其实没有真正掌握正确处理异常情况的方法和策略,最多也就不过了解个大概,知道概念.我想对 ...
- ASP.NET MVC Identity 使用自己的SQL Server数据库
之前在网上看到的一篇后来找不到了,现在自己记录一下. 1.在web.config中添加一个数据库连接. <add name="dataContext" connectionS ...
- [转] DataSet的的几种遍历
1. 多表多行多列的情况 foreach (DataTable dt in YourDataset.Tables) //遍历所有的datatable { foreach (DataRow dr in ...
- AndroidStudio怎样导入jar包
来自:http://jingyan.baidu.com/article/e6c8503c7190b7e54f1a1893.html AndroidStudio用于开发安卓Apk非常地方便,但是它的很多 ...
- 1.【nuxt起步】-nuxt是什么?
百度了解下,简单说就是vue的seo化,因为vue是spa,不支持seo,从本地运行的源码可以看出来,html没有tkd和相关文字,导致百度收录困难,所以nuxt可以很好的解决这个问题, 举个例子:纯 ...
- Windows Server 2008R2 设置SMTP邮件转发服务
最近因业务需求在Windows Server 2008R2server上设置SMTP转发服务,主要是在业务审批过程中邮件通知相关人员审批情况, 1.在server上加入服务 2.打开服务 3.新建一个 ...
- Ubuntu 安装 spark
环境: Unbunt 12.04 Hadoop 2.2.x Sprak 0.9 Scala scala-2.9.0.final.tgz 步骤 1. 下载 scala 2. 解压scala,然后改动/e ...
- hdu5340 Three Palindromes(manacher算法)
题目描写叙述: 推断能否将字符串S分成三段非空回文串. 解题思路: 源码: #include <cstdio> #include <algorithm> #define MAX ...
- react-redux 和 redux-saga 小结
react-redux 将 store 绑定到 props 上,便于全局调用. redux-saga 是将 redux 的同步转换为异步. 注: dispatch 到 saga , saga 匹配行为 ...
- AVOS Cloud 技术支持系统开源了
非常高兴跟大家说.工单系统(技术支持系统)开源了.代码托管在了Github上. 假设还未见识过工单系统,请移步于 https://ticket.avosapps.com/ 这个系统是用 AVOS Cl ...