zoukankan      html  css  js  c++  java
  • CF1217B Zmei Gorynich

    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 h_i 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=10d=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=10d=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 tt independent queries.

    Input

    The first line contains one integer t (1t100) – the number of queries.

    The first line of each query contains two integers nn and x (1n1001x10^9) — the number of possible types of blows and the number of heads Zmei initially has, respectively.

    The following nn lines of each query contain the descriptions of types of blows you can deal. The ii-th line contains two integers d_i and h_i (1d_i,h_i109) — 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.

    Example
    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 106+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行每行输入两个整数d-i和h_i。分别是一回合能造成的damage和造成伤害后怪物回复的hp,怪物总hp是x点。

    思路是贪心,先选出一个最大的max_d_i判断与x的关系,在对d_i-h_i排个序,<0则一定有解。

    下面给出代码

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    struct ss
    {
        long long a;
        long long b;
    }e[505];
    inline bool cmp(const ss&A,const ss&B)
    {
        return A.a>B.a;
    }
    int main()
    {
        int t;
        scanf("%d",&t);
        for(int i=1;i<=t;++i)
        {
            ll n,m;
            cin>>n>>m;
            ll mmax=1;
            for(int j=0;j<n;++j)
            {
                long long x,y;
                cin>>x>>y;
                e[j].a=x-y;
                e[j].b=x;
                mmax=max(mmax,x);
            }
            sort(e,e+n,cmp);
            m-=mmax;
            if(m<=0)
            {
                cout<<1<<endl;continue;
            }
            if(e[0].a>0)
            {
                int tt=m/e[0].a+2;
                if(m%e[0].a==0)
                {
                    tt--;
                }
                cout<<tt<<endl;
            }
            else
            {
                cout<<-1<<endl;
            }
        }
        return 0;
    }
    View Code

    做这题时混用了scanf和cin,为了加速关闭了文件流同步,最后就疯狂RE,切忌偷懒啊。

  • 相关阅读:
    ffmpeg学习笔记-ffmpeg在VS下的运用
    ffmpeg学习笔记-初识ffmpeg
    ffmpeg学习笔记-初识ffmpeg
    NDK学习笔记-使用现有so动态库
    新闻cms管理系统(一) ---- thinkphp框架准备
    新闻cms管理系统功能介绍
    ubuntu中phpstorm和sublime快速启动
    ubuntu使用----高效快捷键
    windows下使用docker(一)—— 安装
    windows下更新npm的命令实现
  • 原文地址:https://www.cnblogs.com/yoududezongzi/p/11509659.html
Copyright © 2011-2022 走看看