Codeforces Round #200 (Div. 2)344C Rational Resistance(模拟)
来源:互联网 发布:网络劫持修复工具 编辑:程序博客网 时间:2024/04/29 13:53
输入两个数a, b 通过串联或并联单位电阻使电阻成为a / b,输出最小电阻数。
要注意题目给的两个公式,R0是单位电阻,Re是你计算出来的电阻。先判断输入的是否大于1,若大于则转换成小于1的分数,然后一
步一步减小分母,而后交换分子分母,直到分母或分子为1,因为为1的时候才可以直接加。
AC代码:
#include "iostream"#include "cstdio"#include "cstring"#include "algorithm"using namespace std;typedef long long ll;ll a, b;int main(int argc, char const *argv[]){cin >> a >> b;if(a == b) {cout << 1 << endl;return 0;}ll ans = (ll)(a / b), cur = 0;a -= ans * b;while(true) {if(a == 1) {ans += b;break;}if(b == 1) {ans += a;break;}cur += (ll)(b / a);b %= a;swap(a, b);}cout << ans + cur << endl;return 0;}
1 0
- Codeforces Round #200 (Div. 2)344C Rational Resistance(模拟)
- Codeforces Round #200 (Div. 2) C. Rational Resistance
- Codeforces Round #200 (Div. 2) C. Rational Resistance(脑洞思维)
- Codeforces 344C - Rational Resistance
- CodeForces - 344C Rational Resistance (模拟题 +递归求解)
- Codeforces 344C Rational Resistance【思维+贪心】
- codeforces #200 div2.C Rational Resistance [思维]
- Codeforces Round #346 (Div. 2) C模拟
- Codeforces Round #325 (Div. 2) C 模拟
- Codeforces Round #316 (Div. 2) C 模拟
- Codeforces Round #306 (Div. 2) C 模拟
- Codeforces Round #126 (Div. 2) C 模拟
- Codeforces Round #373 (Div. 2) C 模拟
- Codeforces Round #377 (Div. 2) C 模拟
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) C 模拟
- C. Rational Resistance
- Codeforces Round #138 (Div. 2) c 数据结构模拟
- Codeforces Round #306 (Div. 2)C. Divisibility by Eight--模拟
- 重庆老烂腿老烂腿
- 悄悄告诉Facebook产品的开发流程
- 重庆老烂腿手术危险吗
- swift -变量的定义与使用
- HDU 5373 The shortest problem(判断一个数能否被11整除)
- Codeforces Round #200 (Div. 2)344C Rational Resistance(模拟)
- Android studio 报错 gradel project sync failed Error:Cause: peer not authenticated
- 重庆轻度老烂腿怎么治
- HDU 5067 Harry And Dig Machine (DFS)
- 重庆小腿老烂腿中医
- LeetCode总结
- C黑白棋
- 重庆脚上老烂腿怎么治疗
- 重庆老烂腿医院那个好