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=

随便看看

thinkphp3.2配置redis缓存和文件缓存

如果您将一些常用但不易更改的数据存储在缓存中,而不是每次检查数据库,则可以大大减轻数据库的压力。最近,由于项目的需要,您尝试了Redis,但后来使用tp3.2文件缓存直接进入主题:在config中添加以下代码。php:“DATA_CACHE_PREFIX”=˃“tp”,//缓存前缀“DATA_CCACHE_TYPE”=˃“Redis”,//高速缓存类型“Re...

为服务中网关的作用

“API网关”核心组件是架构用于满足此些需求。API网关定位为应用系统服务接口的网关,区别于网络技术的网关,但是原理则是一样。API网关统一服务入口,可方便实现对平台众多服务接口进行管控,对访问服务的身份认证、防报文重放与防数据篡改、功能调用的业务鉴权、响应数据的脱敏、流量与并发控制,甚至基于API调用的计量或者计费等等。...

Flutter——数组以符号隔开转字符串

///数组转换为字符串StringgetTaskScreen(Listlist){ListtempList=List();Stringstr='';List.forEach((f){tempList.add(f.title);});临时列表。forEach((f){if(str==“”){str=“$f”;}否则{str=“$str”,“$f”;}});re...

Docker Compose 版本过高(Docker版本不匹配),降低docker-compose版本

好了,开始降级docker-compose,先卸载:#pipuninstalldocker-compose再安装指定版本:#pipinstalldocker-compose==1.5.2至此,docker-compose降版本成功!...

凤凰系统(Phoenix OS)PC版安装,电脑上体验功能丰富的安卓系统

Tid=9074&fid=12安装前准备下载最新的PhoenixOSIO安装映像,并将其刻录到USB闪存驱动器;如果使用Windows操作系统,建议使用UltraISO刻录。下载地址:http://www.phoenixos.com/download_x86开始安装。1.重新启动机器,从启动选项中选择USB闪存磁盘启动,然后选择“Installati...

(二)Jenkins配置主从节点实例

4.从节点配置和相关配置中从节点机创建jenkins用户,并从一些环境配置中创建jenkings用户的ssh密钥,用于指定上述配置界面的ssh启动模式;在配置启动模式和项目源代码管理中从远程仓库获取源代码;创建Jenkins用户并使用root登录到远程子节点计算机。#adduserjenkins#passwdjenkins生成Jenkins用户的ssh密钥。...