GYM
来源:互联网 发布:酒店网络营销策划方案 编辑:程序博客网 时间:2024/06/02 01:51
题意:两人轮流攻击,主角每次只能闪避一个攻击,闪避后要休息一秒…问主角什么时候死。
解题思路:比较容易想到的是,两个数的最小公倍数就是答案。但是当两个数互质的时候就不是了,nx+my=1,实际上就是求这个方程的解。扩展欧几里得即可。
#include <iostream>#include <algorithm>#include <string>#include <vector>#include <memory.h>#include <bitset>#include <map>using namespace std;typedef long long int ll;ll N, M;ll exgcd(ll a, ll b, ll &x, ll &y){ if (b == 0) { x = 1; y = 0; return a; } ll ans = exgcd(b, a % b, x, y); ll tmp = x; x = y; y = tmp - a / b * y; return ans;}int main(){ ios::sync_with_stdio(false); cin >> N >> M; ll x, y; ll g = exgcd(N, M, x, y); ll ans = N * M / g; if (N == 1 || M == 1) { if (N == M) cout << "1" << endl; else cout << "2" << endl; return 0; } if (g == 1) ans = min(ans, max(abs(x * N), abs(y * M))); cout << ans << endl; return 0;}
阅读全文
0 0
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- python os.path模块
- People类中添加Speak()方法
- Windows 下线程的设置
- BZOJ3944 Sum 杜教筛
- java集合框架之学生成绩排序
- GYM
- Android 面试
- README
- 符合ASIL D的AUTOSAR基础软件带来的安全和性能
- 机器学习实战-之SVM核函数与案例
- 机器学习实战 决策树代码 计算香农熵 Error return arrays must be of ArrayType
- angular框架的SmartAdmin模板 如何请求后台数据
- 575. Distribute Candies
- git 常用命令