【NOIP2012模拟10.9】电费结算(electric)
来源:互联网 发布:android 仿淘宝首页 编辑:程序博客网 时间:2024/04/30 02:37
Description
WZK最近靠租房发家致富了。作为WZK老同学的你也要租房,于是WZK决定不要房租,但是电费还得付。以下是用电价格:
举个例子吧。如果你用电为10123千瓦时,那么要付2 * 100 + 3 * 9900 + 5 * 123 = 30515块钱(好贵)。到结算电费的日子了,可是WZK家里只有一个总电表,也就是统计你和WZK总共用的电量。但是WZK有办法告诉你以下信息:
1).如果按照总电表来看要交给供电局的钱A。(也就是两个人用电量加起来一起算钱)
2).你和WZK如果分开付的话,你们付的钱的差值B。现在你想知道如果你单独算钱的话,需要付多少钱。当然,你的用电量不会比WZK多。举个例子:如果你们一起算钱要付1100,并且如果分开来算,你们的差值是300的话,那么你用了150kwh,WZK用了250kwh。让我们来验算一下:你们一共用电400kwh,所以要付2 * 100 + 3 * 300 = 1100,你单独要付2 * 100 + 3 * 50 = 350,WZK单独要付2 * 100 + 3 * 150 = 650。所以最后,你只需要告诉我你单独要付350元。
Input
输入仅一行,包含两个整数A和B(1 ≤ A, B ≤ 10^9),含义同上。 输出描述: 输出仅一行一个整数,代表你单独算需要付的钱。数据保证解唯一。
Output
输出仅一行一个整数,代表你单独算需要付的钱。数据保证解唯一。
Sample Input
1100 300
Sample Output
350
Data Constraint
Hint
20%的数据,A和B都不超过10^6。100%的数据,1 ≤ A, B ≤ 10^9。
题解:
模拟,先把钱转化成电量,应为他比WZK用电少,所以二分查找答案。
代码:
var n,m,dian:longint;procedure init;var x:longint;begin readln(n,m); x:=n; if x>200 then begin x:=x-200;dian:=dian+100;end else begin dian:=dian+x div 2;x:=0;end; if x>29700 then begin x:=x-29700;dian:=dian+9900;end else begin dian:=dian+x div 3;x:=0;end; if x>4950000 then begin x:=x-4950000;dian:=dian+990000;end else begin dian:=dian+x div 5;x:=0;end; dian:=dian+x div 7;end;function df(x:longint):longint;begin df:=0; if x>100 then begin x:=x-100;df:=df+200;end else begin df:=df+x*2;exit;end; if x>9900 then begin x:=x-9900;df:=df+29700;end else begin df:=df+x*3;exit;end; if x>990000 then begin x:=x-990000;df:=df+4950000;end else begin df:=df+x*5;exit;end; df:=df+x*7;end;function kk(x:longint):longint;begin if df(dian-x)-df(x)>m then kk:=2 else if df(dian-x)-df(x)<m then kk:=1 else kk:=0;end;procedure ef(l,r:longint);var mid,t:longint;begin mid:=(l+r)div 2; t:=kk(mid); if l+1=r then exit; if t=2 then ef(mid,r) else if t=1 then ef(l,mid) else begin writeln(df(mid));exit;end;end;begin init; ef(1,dian div 2);end.
0 0
- 【NOIP2012模拟10.9】电费结算(electric)
- 【NOIP2012模拟10.9】电费结算
- September 24th 模拟赛C T1 电费结算 Solution
- 电费结算 纪中3018 二分
- 电费结算_纪中3018_二分
- noip2012 寻宝 (模拟)
- 【NOIP2012模拟8.20】Memory
- 【NOIP2012模拟8.20】Memory
- 【NOIP2012模拟11.8】刪數
- 【NOIP2012模拟10.27】比赛
- 【NOIP2012模拟10.25】单元格
- 【NOIP2012模拟10.25】剪草
- 【NOIP2012模拟10.25】单元格
- 【NOIP2012模拟10.25】旅行
- 【NOIP2012模拟10.25】剪草
- 【NOIP2012模拟10.25】旅行
- 【NOIP2012模拟10.26】雕塑
- 【NOIP2012模拟10.26】电影票
- 中南大学急诊医学专业2008-2016年考研报录比【汇总】
- Android事件传递的三个方法
- Android 之requestFocus
- Linux Shell echo 参数说明
- 未解决的问题
- 【NOIP2012模拟10.9】电费结算(electric)
- Android 6.0在运行时申请权限解释与实例
- device
- maven的搭建
- LeetCode: Binary Tree Paths
- oracle学习总结-----oracle的介绍
- 什么是脚本语言
- 求n个中选m个的方案数(dp)
- 稀疏矩阵的(普通/快速)转置