Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
来源:互联网 发布:韩信厉害知乎 编辑:程序博客网 时间:2024/05/18 01:45
因为C题卡住了,这次炸了.
我以为模拟肯定T了,所以就写了拓展欧几里得.
然后就被欧几里得坑了.
用拓展欧几里得做,要把横向和纵向运动分开.
x轴:
y轴:
然后把这两个公式展开一下,在拓展欧几里得求一下就完事了.
(调试出翔)
#include <cstdio>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;typedef long long longl;const longl INF=1LL<<60;template <class T> void put(T x) { if (x==0) { return; } put(x/10); putchar(x%10^48);}template <class T> void print(T x) { if (x<0) { putchar('-'),x=-x; } else if (x==0) { putchar('0'); return; } put(x);}int exgcd(int a,int b,int &x,int &y) { if(b==0) { x=1;y=0; return a; } int r=exgcd(b,a%b,x,y); longl t=x;x=y;y=t-1LL*a/b*y; return r;}int N,M;int n,m,k;int x,y,gcd;longl solve(int a,int b) { if ((b-a)%gcd) return INF; int t=(b-a)/gcd; longl k=1LL*x*t; k=(k%m+m)%m; return 2LL*N*k+a;}int main() { int n,m,k; cin>>n>>m>>k; N=n,M=m; n<<=1,m<<=1; gcd=exgcd(n,m,x,y); n/=gcd,m/=gcd; ::n=n,::m=m; exgcd(n,m,x,y); for (int a,b,i=1;i<=k;++i) { longl t=INF; scanf("%d%d",&a,&b); t=min(t,solve(a,b)); t=min(t,solve(a,2*M-b)); t=min(t,solve(2*N-a,b)); t=min(t,solve(2*N-a,2*M-b)); if (t==INF) puts("-1"); else print(t),putchar('\n'); } return 0;}
1 0
- 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 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)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) D. Dense Subsequence
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)【A,B,C,D】
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) D题
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A题
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) -- C. Ray Tracing(STL乱搞)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) -- B. Batch Sort(暴力枚举)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) -- A. Checking the Calendar(思路)
- 3.4修改menu.cpp
- http状态码大全304、201、203等等
- DirectoryInfo类
- 使用IDEA构建Spark Scala开发环境(支持maven)
- 21. Merge Two Sorted Lists
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- stm32 IAP + APP合成一个烧写文件
- HTML标签marquee实现滚动效果
- VC中如何打开Com10及以上的串口
- Android中JNI的使用方法
- database rough 1
- 机器学习小组知识点3:最小二乘法(LSM)
- Linux进程间通信-管道
- redis分布式锁