UESTC 1647 Battery Charging (找规律模拟)
来源:互联网 发布:淘宝大学总裁班怎么样 编辑:程序博客网 时间:2024/05/22 01:33
Description
Recently, qbwj bought a powerful cellphone which performs even better than most computers. He spent lots of time on it. However, this cellphone has a very strange feature which confused qbwj. There is a battery with infinite capacity in the cellphone. On each day, qbwj has three choices: use the cellphone, charge the battery or do nothing. He cannot do using and charging on the same day. Charging on the kth day adds k units of power to the battery. If qbwj chooses to use the cellphone on the kth day, it would consume k units of power. Note that qbwj can choose to use the cellphone if and only if there are enough units of power in the battery.
Despite of the strengths of the cellphone, qbwj couldn't suffer it any more. So he decides to sell it at the end of Tth day. Today is the Sth day and the battery is empty now. He wants to know how many days at maximum he can use the cellphone before selling it out.
Note that qbwj can still choose to use the cellphone on both the Sth day and Tth day.
Input
The first line of the input will be an integer N (N <= 10000) indicating the number of cases.
For each test case, two integers are given on a single line: S T. 1 <= S <= T <= 108.
Output
Print "Case #k: d" in a single line for each test case, in which k represents the case number which starts from 1, and d is the answer.
Sample Input
3
3 6
3 9
1 100000
Sample Output
Case #1: 1
Case #2: 3
Case #3: 49994
Hint
For the first sample, we charge the cellphone on the 3rd, 4th, 5th day and use it on the 6th day.
Source
10th UESTC Programming Contest Final
分析:简单贪心,显然电池能用则用
因为 1、以后用要花费更多的电量;2、以后充电比现在充电要得到更多的电
量。
第 S 天电池没电,充完电之后剩余 S 的电量
第 S+1 天因为电量不够还需要充电,充完电之后剩下 2*S+1 的电量
第 S+2 天使用电池,用完之后剩下 S-1 的电量,以后重复这样的步骤,也就
是说充一天电,使用一天。每进行一次这样的步骤,剩余电量减 1。所以 S 的电
量可以进行 S 次这样的步骤,也就使用了 S 天。第 3*S 天,剩余电量为 0 。然
后第 3*S+1 天又是相同的问题。因为每次 3 倍的增长,直接模拟就好了。
我的代码:
#include<cstdio>#include<cstring>#include<iostream>using namespace std;int main(){ int t,cas=1,k,a,b,ans; scanf("%d",&t); while(t--) { ans=0; scanf("%d%d",&a,&b); while(a<b) { k=3*a; if(k<=b) { ans+=a; a=3*a+1; } else { ans+=(b-a)/2;break; } } printf("Case #%d: %d\n",cas++,ans); }}
- UESTC 1647 Battery Charging (找规律模拟)
- UESTC OJ 1647Battery Charging 模拟题
- UESTC OJ 1647Battery Charging 模拟题
- UESTC Battery Charging (1647 )
- UESTC 568 —— Battery Charging
- Battery Charging
- UESTC 1012 (思维)(找规律)
- UESTC 1900 倒推数组 (找规律)
- cf(找规律,模拟)
- HDU2147(模拟找规律)
- FZU1062(找规律+模拟)
- 二、Driver - Battery Charging
- Battery Charging Summary
- Harmonic Number (II)(模拟找规律)
- UESTC P酱的冒险旅途 785 (规律模拟)
- (较难)Battery Charging(CDOJ1647)
- hdu 1998 奇数阶魔方(找规律+模拟)
- 历届试题 蚂蚁感冒 (找规律模拟)
- 给两个数,求两数中的大者
- 编写一个js函数求一个字符串数组按字符串中各字母出现次数多少的重新排序
- 一个使用简单的工具类
- hoj 1867 水~~~树状数组
- 第7周任务3-输出几何案
- UESTC 1647 Battery Charging (找规律模拟)
- “-”分隔字符串操作
- jsp中全选按钮代码
- windows下表达式计算器C实现
- find函数_打印与第一个参数指定的模式匹配的行(《C程序设计语言》 第二版)
- 史上最短小精悍内涵的小说5篇
- 基于stun, turn, ice协议的NAT穿越
- MFC读取XML文件并解析
- jsp解析中文字符,其中两编一解