zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 72 (Rated for Div. 2) B题

    Problem Description:

    You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads!
    Initially Zmei Gorynich has x heads. You can deal n types of blows. If you deal a blow of the i-th type, you decrease the number of Gorynich's heads by min(di,curX), there curX is the current number of heads. But if after this blow Zmei Gorynich has at least one head, he grows hi new heads. If curX=0 then Gorynich is defeated.
    You can deal each blow any number of times, in any order.
    For example, if curX=10, d=7, h=10 then the number of heads changes to 13 (you cut 7 heads off, but then Zmei grows 10 new ones), but if curX=10, d=11, h=100 then number of heads changes to 0 and Zmei Gorynich is considered defeated.
    Calculate the minimum number of blows to defeat Zmei Gorynich!
    You have to answer t independent queries.
    Input
    The first line contains one integer t (1≤t≤100) – the number of queries.
    The first line of each query contains two integers n and x (1≤n≤100, 1≤x≤109) — the number of possible types of blows and the number of heads Zmei initially has, respectively.
    The following n lines of each query contain the descriptions of types of blows you can deal. The i-th line contains two integers di and hi (1≤di,hi≤109) — the description of the i-th blow.
    Output
    For each query print the minimum number of blows you have to deal to defeat Zmei Gorynich.
    If Zmei Gorynuch cannot be defeated print −1.

    input:

    3
    3 10
    6 3
    8 2
    1 4
    4 10
    4 1
    3 2
    2 6
    1 100
    2 15
    10 11
    14 100

    output:

    2
    3
    -1

    Note
    In the first query you can deal the first blow (after that the number of heads changes to 10−6+3=7), and then deal the second blow.
    In the second query you just deal the first blow three times, and Zmei is defeated.
    In third query you can not defeat Zmei Gorynich. Maybe it's better to convince it to stop fighting?

    题意:T组数据。第一行输入n,x。n,x分别代表技能种类和头的初始数量。n行数据,代表技能的攻击力和恢复力。求砍完头的最小次数。

    思路:贪心。求出(n-x)最大的差值,和最大的攻击力。然后贪心。

    AC代码:

     1 #include<bits/stdc++.h>
     2 // 重点:最后一次用最大攻击力砍掉头 ,其余用差值大的数减 
     3 using namespace std;
     4 #define int long long
     5 #define inf 1<<30
     6 int n,m,ans;
     7 void work(){
     8     int cha=-inf;
     9     int gongjili=-inf;
    10     int a,b;
    11     for(int i=1;i<=n;i++){
    12         cin>>a>>b;
    13         cha=max(cha,a-b);// 最大差值 
    14         gongjili=max(gongjili,a);// 最大攻击力 
    15     }
    16     if(gongjili>=m){// 特判一下 
    17         ans=1;
    18         return ;
    19     }
    20     if(cha<=0){// 判断差值<=0 
    21         ans=-1;
    22         return ;
    23     }
    24     m-=gongjili;
    25     int sum=1;sum+=m/cha;
    26     if(m%cha){
    27         sum++;
    28     }
    29     ans=sum;
    30     return ;
    31 } 
    32 signed main(){
    33     int _;
    34     cin>>_;
    35     while(_--){
    36         cin>>n>>m;// 输入数据 
    37         ans=0;
    38         work();// 
    39         printf("%lld
    ",ans);
    40     }
    41     return 0;
    42 }
  • 相关阅读:
    mysql 存储过程 异常处理机制
    Maven 私服打包
    Flink(2):Flink的Source源
    Flink(1):Flink的基础案例
    最后一课
    我的获奖记录及 Important Dates in OI
    目录
    入坑 OI 三周年之际的一些感想
    洛谷 P3781
    Atcoder Typical DP Contest S
  • 原文地址:https://www.cnblogs.com/pengge666/p/11474371.html
Copyright © 2011-2022 走看看