FZU-2147-2147 A-B Game,规律题。。
Time Limit: 1000 mSec
Memory Limit : 32768 KB
Problem Description
Fat brother and Maze are playing a kind of special (hentai) game by two integers A and B. First Fat brother write an integer A on a white paper and then Maze start to change this integer. Every time Maze can select an integer x between 1 and A-1 then change
A into A-(A%x). The game ends when this integer is less than or equals to B. Here is the problem, at least how many times Maze needs to perform to end this special (hentai) game.
Input
The first line of the date is an integer T, which is the number of the text cases.
Then T cases follow, each case contains two integers A and B described above.
1 <= T <=100, 2 <= B < A < 100861008610086
Output
For each case, output the case number first, and then output an integer describes the number of times Maze needs to perform. See the sample input and output for more details.
Sample Input
Sample Output
规律很好找,求多少次A-(A%X)<=B;也就是求A%X的最大值,这样减的次数才会尽可能少,于是枚举了几组数据,发现当X=A/2+1时,A%X最接近A;于是规律出来了;
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
//const int N=101;
//char a[N][N];
int main()
{
int t,i;
long long a,b,x;
scanf("%d",&t);
int t1=t;
while(t--)
{
x=i=0;
scanf("%I64d%I64d",&a,&b);
while(a>b)
{
i++;
x=a/2+1;//关键找到这个规律;
a-=a%x;
}
printf("Case %d: ",t1-t);
printf("%d\n",i);
}
return 0;
}
FZU-2147-2147 A-B Game,规律题。。的更多相关文章
- LightOJ1010---Knights in Chessboard (规律题)
Given an m x n chessboard where you want to place chess knights. You have to find the number of maxi ...
- Codeforces - 规律题 [占坑]
发现自己容易被卡水题,需要强行苟一下规律题 CF上并没有对应的tag,所以本题集大部分对应百毒搜索按顺序刷 本题集侧重于找规律的过程(不然做这些垃圾题有什么用) Codeforces - 1008C ...
- ACM_送气球(规律题)
送气球 Time Limit: 2000/1000ms (Java/Others) Problem Description: 为了奖励近段时间辛苦刷题的ACMer,会长决定给正在机房刷题的他们送气球. ...
- hdoj--1005--Number Sequence(规律题)
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 2147 kiki's game(博弈经典题)
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=2147 Problem Description Recently kiki has nothing to ...
- FZU - 2037 -Maximum Value Problem(规律题)
Let’s start with a very classical problem. Given an array a[1…n] of positive numbers, if the value o ...
- 洛谷 P1876 开灯(思维,枚举,规律题)
P1876 开灯 题目背景 该题的题目是不是感到很眼熟呢? 事实上,如果你懂的方法,该题的代码简直不能再短. 但是如果你不懂得呢?那...(自己去想) 题目描述 首先所有的灯都是关的(注意是关!),编 ...
- Codeforces 959E. Mahmoud and Ehab and the xor-MST 思路:找规律题,时间复杂度O(log(n))
题目: 解题思路 这题就是0,1,2...n-1总共n个数字形成的最小生成树. 我们可以发现,一个数字k与比它小的数字形成的异或值,一定可以取到k与所有正整数形成的异或值的最小值. 要计算n个数字的情 ...
- Visible Lattice Points(规律题)【数学规律】
Visible Lattice Points 题目链接(点击) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9031 ...
随机推荐
- Win7系统出现提示: “Windows已遇到关键问题,将在一分钟后自动重新启动。”
1. 若用户在使用Win7系统时,遇到上述系统故障,建议重启电脑.等电脑开机自检一过,马上按键盘上的F8键,选择进入安全模式.在安全模式下,进行系统还原.其他的解决方法见下. 1.或者,在安全模式下, ...
- json和php数组 格式的互相转换
$json_arr = array('WebName'=>'PHP网站开发教程网','WebSite'=>'http://www.jb51.net'); $php_json = json ...
- Ionic开发-如何在ion-content形成上下结构 上面固定下层可滚动
在一个系统设计中,一般有些需要固定位置,便利操作.现在我要做一个上下两层,需要固定上方,下方拉刷新数据. 页面: <ion-content scroll="false"> ...
- Java 设置Word页面背景色
Word中可以针对不同文档排版设计要求来设置背景设置颜色.常见的可设置单一颜色.渐变色或加载指定图片来设置成背景.下面通过Java来设置以上3种Word页面背景色. 使用工具:Spire.Doc fo ...
- SQL异常为"当IDENTITY_INSERT设置为OFF时" 的解决
误删数据库时,可以利用insert插入删除的数据,但是有时表可能有自增字段如id.这是插入数据如果包含自增字段就会出现错误,提示"IDENTITY_INSERT设置为OFF,插入失败&quo ...
- 伟景行 citymaker 从入门到精通(2)——工程图层树加载
工程树是指explorer左边这棵树 本例子实现了图层树加载,点击节点切换可视状态 树控件使用easyui的树 html部分 onCheck:treeProjectTreeOnCheck是指树节点的o ...
- oss图片上传失败
在生产上跑的正常代码,新搭了个测试环境,发现oss上传失败! 开始分析oss是否有以各种类似于白名单的功能,不认识测试域名导致的...结果不是! 改变访问类型 因为oss节点Endpoint是在杭州, ...
- -bash: mysql: command not found 之 MAC
第一次尝试: ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql 提示:Operation not permitted 再次,加sudo附上管理员权限,依旧 ...
- PMP项目管理学习笔记(11)——范围管理之定义范围
定义范围过程组 定义范围包含将项目分解为团队成员要完成的具体工作之前你需要知道的所有一切. 输入:需求文档.项目章程.组织过程资产 工具:辅助工作室.产品分析.代理方案识别.专家判断 辅助工作室: 与 ...
- Eclipse添加默认的JRE
打开eclipse,依次点击如下选项Window->Preferences-> Java -> Installed JREs.步骤见下图. 选中Installed JREs选项出 ...