(较难)Battery Charging(CDOJ1647)
来源:互联网 发布:小米mix2全球网络制式 编辑:程序博客网 时间:2024/05/19 21:17
#include<iostream>#include<stdio.h>using namespace std;#define inf 100000000int main(){ int a,b; int i,j,k; int t; cin>>t; int num=0; while (t--) { num++; scanf("%d%d",&a,&b); k=b-a; int ans=0; printf("Case #%d: ",num); while (true) { if (a+2*a<=b) { ans+=a; a=3*a+1; } else { if (b>=a+2) { ans+=(b-a)/2; } break; } } printf("%d\n",ans); }}
Battery Charging
Time Limit: 1000 ms Memory Limit: 65536 kB Solved:37 Tried: 74
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.
Simple Input
3
3 6
3 9
1 100000
Simple 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
- (较难)Battery Charging(CDOJ1647)
- Battery Charging
- UESTC Battery Charging (1647 )
- 二、Driver - Battery Charging
- Battery Charging Summary
- UESTC OJ 1647Battery Charging 模拟题
- BC 1.2 模式(Battery Charging Specification 1.2)
- Battery Charging Specification 1.2 中文详解
- UESTC 568 —— Battery Charging
- Battery Charging Specification 1.2 中文详解
- UESTC OJ 1647Battery Charging 模拟题
- Battery Charging Specification 1.2 中文详解
- Battery Charging Specification 1.2 中文详解
- Battery Charging Specification 1.2 中文详解
- Battery Charging Specification 1.2 中文详解 USB
- UESTC 1647 Battery Charging (找规律模拟)
- Battery Charging Specification, Revision 1.2, December 7, 2010 中文
- Battery Charging Specification, Revision 1.2, December 7, 2010 中文
- jdk目录中src源文件路径
- 多文件上传————>struts2
- 两个数大小的比较
- c3p0连接池在spring中的配置
- 跨域访问
- (较难)Battery Charging(CDOJ1647)
- SQLServer数据库压缩
- C# 优先采用foreach循环语句
- 1000~2000内能被17与37同时整除的数
- redhat 6.2(x64) 配置tomcat+nginx
- 分苹果问题
- SAP ALV 详细说明 .
- 视频采集的基本流程
- 【Tiny6410 And Linux】—(1.4)—device 设备模型——代码