codeforces 1217b B - Zmei Gorynich

Posted gaudar

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codeforces 1217b B - Zmei Gorynich相关的知识,希望对你有一定的参考价值。

题意:有头龙有m个头,有n种砍法。第i种,砍去ai个,再长bi个。某一时刻头为0胜利。要砍几刀。

先找伤害最大(记为d)的刀和效率(maxv=max(ai-bi))最高的刀。如果d<m且maxv<=0则输出-1.否则最后一刀用伤害最大的一定更优。这样m-d的数值都用效率最高的。

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
#include <unordered_set>
#define mkp make_pair
using namespace std;
const double EPS=1e-8;
typedef long long lon;
typedef pair<lon,lon> pii ;
const lon SZ=100010,SSZ=0,APB=26,INF=0x7FFFFFF,mod=1000000007;
lon n;
lon m;
 
void init()

    cin>>n>>m;
    lon eff=0,str=0,ok=0;
    for(lon i=1;i<=n;++i)
    
        lon dec,inc;
        cin>>dec>>inc;
        if(dec>=m)
        
            ok=1;
        
        if(dec>inc)ok=1;
        eff=max(eff,dec-inc);
        str=max(str,dec);
    
    if(ok==0)cout<<-1<<endl;
    else
    
        if(str>=m)cout<<1<<endl;
        else
        
            lon rem=m-str;
            lon res=rem/eff+(rem%eff!=0)+1;
            cout<<res<<endl;
        
    

 
void work()

    

 
int main()

    std::ios::sync_with_stdio(0);
    //freopen("d:\\1.txt","r",stdin);
    lon casenum;
    cin>>casenum;
    for(lon tim=1;tim<=casenum;++tim)
    
        init();
        work();
    
    return 0;

 

以上是关于codeforces 1217b B - Zmei Gorynich的主要内容,如果未能解决你的问题,请参考以下文章

CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26

Codeforces Educational Codeforces Round 52

Codeforces Round #340 (Div. 2) B

Educational Codeforces Round 7 B

codeforce B

Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)