Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing 数学
来源:互联网 发布:2017爱情电影 知乎 编辑:程序博客网 时间:2024/04/30 13:06
题意
有一个球,一开始从00点开始发射,速度向量为(1,1),在一个nm的矩形里面弹来弹去
然后k个询问,问你第一次遇到这个点的时间是多少
题解:
其实可以转换成一个同余方程,然后求解就好了。
方程实际上是,x%2n=x0,x%2m=y0,显然可以转化为同余方程,exgcd求解就好了
#include<bits/stdc++.h>using namespace std;typedef long long ll;const long long INF=1e16;ll extend_gcd(ll a,ll b,ll &x,ll &y){ ll d=a; if(b!=0) { d=extend_gcd(b,a%b,y,x); y-=(a/b)*x; } else { x=1; y=0; } return d;}ll xx,yy;long long solve(int x, int y){ long long N = 2 * xx, M = 2 * yy; long long X, Y; long long g = extend_gcd(N, M, X, Y); if ((y - x) % g != 0) return INF; long long lcm = 1ll * N * M / g; X *= (y - x) / g; long long x0 = X % lcm * N % lcm + x; x0 = (x0 % lcm + lcm) % lcm; if (x0 == 0) x0 += lcm; return x0;}int main(){ int k; scanf("%lld%lld%d",&xx,&yy,&k); long long t=min({solve(xx,yy),solve(0,0),solve(0,yy),solve(xx,0)}); while(k--) { long long xxx,yyy; cin>>xxx>>yyy; long long tt=min({solve(xxx,yyy),solve(2*xx-xxx,yyy),solve(xxx,2*yy-yyy),solve(2*xx-xxx,2*yy-yyy)}); if(tt<t&&tt<INF)cout<<tt<<endl; else cout<<"-1"<<endl; }}
0 0
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing 数学
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) -- C. Ray Tracing(STL乱搞)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing 模拟
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing 模拟+预处理、几何
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)【A,B,C,D】
- Codeforces Round Intel Code Challenge Final Round C. Ray Tracing
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)
- Coderforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort
- Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- Spinner中的文字居中
- C#类的访问修饰符 161018
- golang实践-目录结构与工具
- cubieboard2 GPIO的使用
- ROW_NUMBER() 的实际应用
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing 数学
- JDBC
- nginx+tomcat实现单个IP地址,多个二级域名+多个站点访问
- android stuido Android ButterKnife Zelezny 插件不提示的问题
- JS第九天 网页特效2
- 【留学必读】雅思考试提分技巧搬个板凳凑热闹
- JAVA程序发布到Docker的fabfile
- SQL语句级别的优化总结
- SpringBoot-SpringData-ManyToMany