[CodeForces318C]Perfect Pair[模拟][暴力]
来源:互联网 发布:91熊猫桌面软件 编辑:程序博客网 时间:2024/06/05 07:57
题目链接:[CodeForces318C]Perfect Pair[模拟][暴力]
题意分析:给出一对数(x,y),每次可进行操作,用x + y替换其中的一个值,问最少多少次操作可以使得x和y中有一个值 >= m。输出最小次数,否则输出-1。
解题思路:直接根据题意模拟,优先把大的往小的加。注意到x= 1, y = -999999999这种情况。等两者都是正数后,后期相加的增长速度就很快了。
个人感受:在样例10的时候TLE了,原来是没把ans设为长整型,另外,之前的思路也没理清楚,WA了一堆。。。。。
具体代码如下:
#include <iostream>using namespace std;typedef long long ll;//让a保持在最小,优先大的加到小的上int main() { ll a, b, m, ans; cin >> a >> b >> m; if (a > b) swap(a, b); if (m <= a || m <= b) cout << 0 << '\n'; else if (b <= 0) cout << -1 << '\n'; else { ans = 0; if (a < 0) { ans = -a / b; //负数直接手动处理掉 a += ans * b; } while (a < m && b < m) { ++ans; a += b; if (a > b) swap(a, b); } cout << ans << '\n'; } return 0;}
0 0
- [CodeForces318C]Perfect Pair[模拟][暴力]
- Gym 101341H Perfect Ban 暴力模拟|签到
- [cf]Perfect Pair
- A. Perfect Pair
- codeforces 317 A Perfect Pair
- cf 317A. Perfect Pair
- HDOJ 1334 Perfect Cubes(暴力)
- [模拟]Perfect Hash UVA188
- [UVA10245] The Closest Pair Problem && 暴力版本
- URAL 2019 Pair: normal and paranormal 暴力?
- POJ 1543 Perfect Cubes 纯暴力
- Perfect pair of jeans did not fit his body type
- uva 188 - Perfect Hash 模拟
- HDU **** 暴力模拟
- HLJUOJ1117(暴力模拟)
- uva10273(暴力模拟)
- HDU2555(模拟暴力)
- uva1504(模拟+暴力)
- 在xml文件中使用自己的标签。
- 单例带来的线程安全问题
- Myeclipse修改文件默认打开方式 jsp xml
- Java serverlet 学习笔记
- WebView 报 Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 3777 (WebViewCoreThre)
- [CodeForces318C]Perfect Pair[模拟][暴力]
- eclipse主题配置。
- 第四节:菜单的使用
- 深入浅出JMS(一)——JMS简介
- caffe 的损失函数 loss 原文解析-多个损失函数 loss 网络搭建
- Victoria的舞会
- <c:forEach>标签的使用方法
- hadoop2.6 和hive1.2
- 联诚发(LCF)P4全彩LED“环绕显示”震撼耀目贵阳夜空