POJ
来源:互联网 发布:淘宝穿过的鞋子退货 编辑:程序博客网 时间:2024/06/05 07:44
本来以为很水,两个蛙蛙之间正向逆向距离 除 速度差就好了,但是不对,还得考虑他们转过好多圈以后 (多少圈不确定,解方程呗)
输入 x, y, m, n, r => 假设他们走了 i 步, 转了 j 圈 ==> m*i - n*i = (x - y)+ r * j ; ==> (m-n) * i + r * j = (x - y)
#include<iostream>#include<cstdio>using namespace std;typedef long long LL;LL x, y, m, n, r, d;void find_(LL a, LL b, LL &g, LL &x, LL &y) { if(!b) { g = a; x = 1; y = 0; return; } find_(b, a%b, g, y, x); y -= (a/b) * x;}int main() { //cout << -1%1 << endl; scanf("%lld%lld%lld%lld%lld", &x, &y, &m, &n, &r); LL x_, y_; find_(n-m, r, d, x_, y_); //cout << d << endl; if((x-y) % d) { cout << "Impossible" << endl; return 0; } x_ *= (x-y)/d; LL t = r / d; x_ = ( x_%t + t ) % t; cout << x_ ; return 0;}
阅读全文
1 0
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- 排序算法(5)选择排序
- 二十分钟读懂JSON
- C#根据类名获取属性名和DESCRIPTION值
- MAC 上Nginx环境搭建
- Java复习题集(三)
- POJ
- HTML iframe用法
- JavaScript——变量
- Windows下安装python版的XGBoost教程(基于Anaconda)
- Greenplum pg_hba.conf entry for host "192.168.2.111", user "gpadmin", database "template1", SSL off
- codeforces #378C(733.C) Epidemic in Monstropolis
- Kafka 踩坑记录
- VS2013中如何解决error C4996: 'fopen'问
- debian8.8建立samba服务器与win7共享文件