zoukankan      html  css  js  c++  java
  • AtCoder

    You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is hi at the moment of encounter. A monster will vanish immediately when its health drops to 0 or 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 by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A>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 with 8 health. The healths of the four monsters become 341 and −1, respectively, and the last monster vanishes.
    • Second, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0−1 and −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

    二分啊啊啊 这么大的数 不二分怎么写
     1 #include <iostream>
     2 using namespace std;
     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 long  n,a1,b1;
    19 long  panduan(long long  zhi)
    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 int  main()
    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 long  mid;
    43     //cout<<panduan(3)<<"_"<<endl;
    44     int t;
    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
  • 相关阅读:
    AjaxWebService返回ArrayList
    Android中将布局文件/View添加至窗口过程分析 从setContentView()谈起
    Andriod中绘(画)图Canvas的使用详解
    Android中获取正在运行的应用程序ActivityManager.RunningAppProcessInfo类详解
    Android 应用程序模块: 应用, 任务, 进程, 和线程
    Android中获取正在运行的服务ActivityManager.RunningServiceInfo的使用
    android面试题整理
    Android中获取系统内存信息以及进程信息ActivityManager的使用(一)
    Android中View绘制流程以及invalidate()等相关方法分析
    android:windowSoftInputMode详解
  • 原文地址:https://www.cnblogs.com/dulute/p/7966703.html
Copyright © 2011-2022 走看看