FZU 2147 A-B Game
来源:互联网 发布:mab软件 编辑:程序博客网 时间:2024/06/04 23:19
H - A-B Game
题目链接
题目大意:输入两个长整型的数a,b。有一种将a变化的操作为:a=a-(a%x), 其中 1<=x<=a-1;
问最少有多少次操作才能使得a<=b。
思路:贪心
因为每次操作a=a-(a%x),1<=x<=a-1,要是操作数最好,那么每次a-(a%x)应该最小。
看如下变形:因为a%x=a-(a/x)*x, 则a-(a%x)=(a/x)*x;要使其最小,x=a/2+1时,(a/x)*x最小。
/** author:liuwen*///#pragma comment(linker, "/STACK:102400000,102400000")#include <iostream>#include <sstream>#include <cstring>#include <cstdio>#include <cstdlib>#include <cmath>#include <climits>#include <queue>#include <stack>#include <map>#include <vector>#include <algorithm>using namespace std;int main(){ //freopen("in.txt","r",stdin); int T,cas=0; scanf("%d",&T); while(T--){ long long a,b,x; cin>>a>>b; int tot=0; while(a>b){ tot++; x=a/2+1; a=(a/x)*x; } cout<<"Case "<<++cas<<": "<<tot<<endl; } return 0;}
0 0
- FZU 2147 A-B Game
- FZU 2147 A-B Game
- FZU-2147 A-B Game
- FZU 2147A-B Game
- FZU 2147 A-B Game
- FZU-Problem 2147 A-B Game
- 【瞎搞】 FZU 2147 A-B Game
- FZU - 2147 A-B Game(找规律)
- FZU-2147-2147 A-B Game,规律题。。
- FZU Problem 2147 A-B Game (数学啊)
- FZU OJ 2147 A-B Game (数学水题)
- FZU 2147 A-B Game(数学推导题)
- fzu 2146 Easy Game & 2147 A-B Game & 2151 OOXX Game(水题)
- FZU A-B problem
- Another a+b FZU
- Foj 2147 A-B Game
- Problem 2147 A-B Game
- B OOXX Game(FZU 2151)
- 为Android性能优化——布局优化
- [!] Pod::Executable clone 'https://github.com/CocoaPods/Specs.git' master
- 超链接点击,移动至上方,点击过的css效果
- Linux 系统安全性能检查小记
- fzu 2148 Moon Game
- FZU 2147 A-B Game
- SRM 552 - 500 FoxAndFlowerShopDivOne
- FZU 2150 Fire Game(枚举两个源点的bfs)
- FZU 2151 OOXX Game
- Android性能优化的——Java(Android)代码优化
- spring-mybatis配置
- Android性能优化的——数据库性能优化
- C#生成高清缩略图
- Windows7部署Android开发环境傻瓜式教程(Eclipse+ADT)