AtCoder

摘要:
Youaregoingoutforawalk,whenyousuddenlyencounterNmonsters.Eachmonsterhasaparametercalledhealth,andthehealthofthei-thmonsterishiatthemomentofencounter.Amonsterwillvanishimmediatelywhenitshealthdropsto0o

You are going out for a walk, when you suddenly encounterNmonsters. Each monster has a parameter calledhealth, and the health of thei-th monster ishiat the moment of encounter. A monster will vanish immediately when its health drops to0or below.

Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:

  • Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease byA, and the health of each of the other monsters will decrease byB. Here,AandBare predetermined parameters, andA>Bholds.

At least how many explosions do you need to cause in order to vanish all the monsters?

Constraints

  • All input values are integers.
  • 1≤N≤105
  • 1≤B<A≤109
  • 1≤hi≤109

Input

Input is given from Standard Input in the following format:

N A B
h1
h2
:
hN

Output

Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.

Sample Input 1

4 5 3
8
7
4
2

Sample Output 1

2

You can vanish all the monsters in two explosion, as follows:

  • First, cause an explosion centered at the monster with8health. The healths of the four monsters become3,4,1and−1, respectively, and the last monster vanishes.
  • Second, cause an explosion centered at the monster with4health remaining. The healths of the three remaining monsters become0,−1and−2, respectively, and all the monsters are now vanished.

Sample Input 2

2 10 4
20
20

Sample Output 2

4

You need to cause two explosions centered at each monster, for a total of four.

Sample Input 3

5 2 1
900000000
900000000
1000000000
1000000000
1000000000

Sample Output 3

800000000
二分啊啊啊 这么大的数 不二分怎么写
AtCoder第1张AtCoder第2张
1 #include <iostream>
2 using namespacestd;
3 #include<string.h>
4 #include<set>
5 #include<stdio.h>
6 #include<math.h>
7 #include<queue>
8 #include<map>
9 #include<algorithm>
10 #include<cstdio>
11 #include<cmath>
12 #include<cstring>
13 #include <cstdio>
14 #include <cstdlib>
15 #include<stack>
16 #include<vector>
17 long long  a[51000000];
18 long longn,a1,b1;
19 long  panduan(long longzhi)
20 {
21     long long  t=b1*zhi;
22     long long  add=0;
23     for(int i=1;i<=n;i++)
24 {
25         if(a[i]-t>0)
26 {
27             if((a[i]-t)%(a1-b1)==0)
28                 add+=(a[i]-t)/(a1-b1);
29             else
30                 add+=(a[i]-t)/(a1-b1)+1;
31 }
32 }
33     //cout<<zhi<<"_"<<add<<endl;
34     return add<=zhi;
35 }
36 intmain()
37 {
38     cin>>n>>a1>>b1;
39     for(int i=1;i<=n;i++)
40         scanf("%d",&a[i]);
41     long long  kaishi=0,jieshu=1e9;
42     long longmid;
43     //cout<<panduan(3)<<"_"<<endl;
44     intt;
45     while(kaishi<jieshu-1)
46 {
47         //cout<<kaishi<<"_"<<jieshu<<endl;
48         mid=(jieshu+kaishi)>>1;
49         if(panduan(mid))
50 {
51             jieshu=mid;
52             t=mid;
53 }
54         else
55             kaishi=mid;
56 }
57     cout<<jieshu<<endl;
58     return 0;
59 }
View Code

免责声明:文章转载自《AtCoder》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇C# 判断对象里所有属性的值是否存在空值分辨率与比例尺下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

微信扫码网页登录,redirect_uri参数错误解决方法

对于微信开放平台[管理中心/应用程序详细信息]中设置的[开发信息][授权回调域],只需填写域名,无需https://,也无需特定页面。您不需要填写完整的请求路径,如图所示:https://open.weixin.qq.com/connect/qrconnect?appid=您的APPID&direct_Uri=回调和响应的特定地址_type=code...

db2字符串函数

可以指定可选的字符串长度单位,以指示哪些单位表示函数的起始位置和结果。使用基于字符的函数解决了将字节位置返回到字符位置的问题。代码单元16和代码单元32根据字符数计数。类似地,CODEUNITS32指定使用Unicode UTF-32来理解多字节字符的字符边界。如果使用CODEUNITS获取字符长度,则用作字符串函数输入的不同CODEUNITS将导致不同的输...

华为交换机堆叠配置

请参考华为交换机的配置堆栈。[Leaf1-stack-port0/1]portinterfaceg0/0/12启用物理接口12加入堆栈组[Leaf1]stackslot0priority255修改优先级255,默认值为100警告:不要频繁修改优先级,因为它会使堆栈分裂。持续...

WinForm 中 comboBox控件之数据绑定

作为列表类型,public class Info{public string Id{get;Name=“Li Si”};infoList.Add(info3);...

uniapp安卓真机调试提示检测不到手机【解决办法】

以下是具体的解决方案:步骤1:打开、查找、单击并单击7次或更多次,以允许开发人员进行选择。...

jenkins之部署、启动、关闭

jenkins可以通过内置的应用服务器或者借助其他应用服务器启动目录1、启动jenkins2、关闭jenkins3、重启jenkins4、重新加载jenkins配置信息前言:部署jenkins应用,是要安装java的,最新版本的jenkins是需要按照1.8版本的jdk,不然启动不了。...