It’s year 2100. Electricity has become very expensive. Recently, your electricity company raised the power rates once more. The table below shows the new rates (consumption is always a positive integer):

Range Price
(Crazy-Watt-hour) (Americus)
1 ∼ 100 2
101 ∼ 10000 3
10001 ∼ 1000000 5
> 1000000 7

This means that, when calculating the amount to pay, the first 100 CWh have a price of 2 Americus each; the next 9900 CWh (between 101 and 10000) have a price of 3 Americus each and so on.
    For instance, if you consume 10123 CWh you will have to pay 2 × 100 + 3 × 9900 + 5 × 123 = 30515 Americus.
    The evil mathematicians from the company have found a way to gain even more money. Instead of telling you how much energy you have consumed and how much you have to pay, they will show you two numbers related to yourself and to a random neighbor:

A: the total amount to pay if your consumptions were billed together; and
B: the absolute value of the difference between the amounts of your bills.

If you can’t figure out how much you have to pay, you must pay another 100 Americus for such a “service”. You are very economical, and therefore you are sure you cannot possibly consume more than any of your neighbors. So, being smart, you know you can compute how much you have to pay. For example, suppose the company informed you the following two numbers: A = 1100 and B = 300. Then you and your neighbor’s consumptions had to be 150 CWh and 250 CWh respectively. The total consumption is 400 CWh and then A is 2×100+ 3×300 = 1100. You have to pay 2×100+ 3×50 = 350 Americus, while your neighbor must pay 2 × 100 + 3 × 150 = 650 Americus, so B is |350 − 650| = 300.
    Not willing to pay the additional fee, you decided to write a computer program to find out how much you have to pay.
Input
The input contains several test cases. Each test case is composed of a single line, containing two integers A and B, separated by a single space, representing the numbers shown to you (1 ≤ A, B ≤ 109). You may assume there is always a unique solution, that is, there exists exactly one pair of consumptions that produces those numbers.
    The last test case is followed by a line containing two zeros separated by a single space.
Output
For each test case in the input, your program must print a single line containing one integer, representing the amount you have to pay.
Sample Input
1100 300
35515 27615
0 0
Sample Output
350
2900

问题链接:UVA12190 LA4476 Electric Bill
问题简述:(略)
问题分析:二分搜索问题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA12190 LA4476 Electric Bill */#include <bits/stdc++.h>using namespace std;typedef long long LL;
const int INF = 1e9;
int a[] = {0, 100, 10000, 1000000, INF};
int cost[] = {0, 2, 3, 5, 7};
int L = sizeof a / sizeof a[0] - 1;LL calc(int n)
{LL t = 0;for (int i = 1; i <= L; i++) {int t2 = min(a[i] - a[i - 1], n);t += LL(t2) * cost[i];n -= t2;}return t;
}int main()
{int a, b;while (~scanf("%d%d", &a, &b) && (a || b)) {int t = 0, left = 0, right = a, mid;while (left <= right) {mid = (left + right) / 2;if (calc(mid) > a) right = mid - 1;else left = mid + 1, t = mid;}int ans = 0;left = 0, right = t / 2;while (left <= right) {mid = (left + right) / 2;if(calc(t - mid) - calc(mid) > b) left = mid + 1;else right = mid - 1, ans = mid;}printf("%lld\n", calc(ans));}return 0;
}

UVA12190 Electric Bill【二分搜索】相关推荐

  1. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  2. CAPEX与OPEX

    最近在做预算,关于CAPEX与OPEX两个概念有时没搞懂,记录下: Capital Expenditure Definition A capital expenditure is for an ite ...

  3. 超级计算机为什么快,演讲视频_为什么这台超级计算机如此快? (有声) _沪江英语...

    Why Is This Supercomputer So Superfast? Cray employees put the finishing touches on Titan at the Dep ...

  4. 【机器学习】模型压缩大杀器!详解高效模型设计的自动机器学习流水线

    作者丨科技猛兽 编辑丨极市平台 导读 本文首先对模型压缩进行了综述,论述目前深度学习存在的挑战,同时对三种高效自动机器流水线方法ProxyLessNAS.AMC和AMC进行了详细的介绍.最后探讨了如何 ...

  5. 超级计算机的英语作文80字,英语作文_为什么这台超级计算机如此快? (有声) _沪江英语...

    Why Is This Supercomputer So Superfast? Cray employees put the finishing touches on Titan at the Dep ...

  6. 树莓派 天猫精灵智能灯泡_智能灯泡即使在关闭时也会用完电吗?

    树莓派 天猫精灵智能灯泡 Smart bulbs are super convenient, and can save you money compared to traditional bulbs. ...

  7. 事务隔离级别脏读幻读_脏读和未提交读隔离级别

    事务隔离级别脏读幻读 In this article, we will discuss the Dirty Read concurrency issue and also learn the deta ...

  8. 外文翻译:Study on Key Technology of Power Users Credit Rating Evaluation Ba(基于大数据的电力用户信用评级评估关键技术研究)

    (博文并非完整版,图片并未能加载,完整版参见 外文翻译:基于大数据的电力用户信用评级评估关键技术研究) ABSTRACT Electricity power supply company has en ...

  9. 电池电量_这是一个黑暗的主题可以节省电池电量的时候

    电池电量 Dark themes are becoming more and more popular. On some devices, they can even save battery pow ...

最新文章

  1. Two Straws May Make a Perfect Diamond: Selecting Individually Weak Features for a Better Accuracy
  2. html获取子节点数量,Selenium-webdriver在JavaScript中获取子元素数
  3. 开发日记-20190623 关键词 休眠(可耻)
  4. 汇编语言笔记10-CALL和RET指令
  5. 【Android UI设计与开发】第16期:滑动菜单栏(一)
  6. addr 与 offset 区别
  7. c++读取txt文件中的数字_在Python中读取包中的数据文件的三种方式
  8. Android 屏幕适配攻略(一)
  9. 2048游戏java教程_java版实现2048游戏功能
  10. 经典贪吃蛇小游戏html代码,js实现经典贪吃蛇小游戏
  11. 理光Ricoh Pro 907EX 一体机驱动
  12. java公倍数_java中如何计算最小公倍数
  13. Git(2)-Git常用的操作和概念
  14. 如何选择回归损失函数
  15. MybatisPlus实现多条件拼接动态查询
  16. 视频gif如何制作?试试这个视频制作gif神器
  17. Unity 旋转人物在设定的角度看向镜头(平滑转动)
  18. 第一模块 jdk与jre、==与equals、Math.round(-1.5)、 String、操作字符串的类、字符串反转、抽象类必须要有抽象方法吗、普通类和抽象类、BIO NIO AIO
  19. 一看就会的Nginx学习教程(千万别告诉其他人),java视频百度云盘
  20. 冲突域和碰撞域的理解

热门文章

  1. 2015-11-19 转载 DPDK支持的网卡类型
  2. oracle支持ipv6,准备现有的网络以支持 IPv6
  3. GIS制图人员的自我修养(2)--制图意识
  4. 技巧篇-图层叠加之美(一)
  5. 使用Python在ArcGIS中编程杂谈
  6. 4个不错的Flash开源项目
  7. Unity推出2D工具:不再只是3D引擎
  8. 关于AIR 应用程序沙箱
  9. Socket,CAsyncSocket,CSocket介绍
  10. 比特币javascript私钥_javascript – 使用bitcoinjs发送比特币交易