• B. Zmei Gorynich ( Educational Codeforces Round 72 (Rated for Div. 2))


    You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads!

    Initially Zmei Gorynich has xx heads. You can deal nn types of blows. If you deal a blow of the ii-th type, you decrease the number of Gorynich's heads by min(di,curX)min(di,curX), there curXcurX is the current number of heads. But if after this blow Zmei Gorynich has at least one head, he grows hihi new heads. If curX=0curX=0 then Gorynich is defeated.

    You can deal each blow any number of times, in any order.

    For example, if curX=10curX=10, d=7d=7, h=10h=10 then the number of heads changes to 1313 (you cut 77 heads off, but then Zmei grows 1010 new ones), but if curX=10curX=10, d=11d=11, h=100h=100 then number of heads changes to 00 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 tt (1t1001≤t≤100) – the number of queries.

    The first line of each query contains two integers nn and xx (1n1001≤n≤100, 1x1091≤x≤109) — 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 didi and hihi (1di,hi1091≤di,hi≤109) — the description of the ii-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−1.

    Example
    input
    Copy
    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
    Copy
    2
    3
    -1
    
    Note

    In the first query you can deal the first blow (after that the number of heads changes to 106+3=710−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?


    分析:给定最初的HP,然后输入n个数据,问最后能不能使得HP<=0。

    (开始理解成n个数据每个只能用一次,使用动归做了一下,也没想去测试一下,WA了之后测试发现题意是可以无限次使用技能,找到次数最少的。测试真的哼重要!!!)


    int main()
    {
        int t,n,m,k,cnt,flag,hp,mxk,mx;
        for(cin>>t;t;t--)
        {
            cin>>n>>m;
            mxk=0,mx=0;
            for(int i=0;i<n;i++)
            {
                cin>>k>>hp;
                mxk = max(mxk,k);
                mx = max(mx,k-hp);
            }
            if(mxk>=m) cout<<1<<endl;
            else if(mx==0) cout<<-1<<endl;
            else
            {
                if( ( m-mxk )%mx )
                    cout<<(m-mxk )/mx+2<<endl;
                else
                    cout<<(m-mxk )/mx+1<<endl;
            }
        }
        return 0;
    }
    所遇皆星河
  • 相关阅读:
    MySQL Thread Pool: Problem Definition
    MySQL数据库InnoDB存储引擎多版本控制(MVCC)实现原理分析
    Mysql源码目录结构
    android学习18——对PathMeasure中getPosTan的理解
    android学习17——命令行建gradle工程
    android学习16——library project的使用
    android学习13——android egl hello world
    ant编译java的例子
    android学习12——重载SurfaceView一些方法的执行顺序
    Visual Studio命令行创建库文件lib
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/11518563.html
Copyright © 2020-2023  润新知