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:


output:


-

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代码:

 #include<bits/stdc++.h>
// 重点:最后一次用最大攻击力砍掉头 ,其余用差值大的数减
using namespace std;
#define int long long
#define inf 1<<30
int n,m,ans;
void work(){
int cha=-inf;
int gongjili=-inf;
int a,b;
for(int i=;i<=n;i++){
cin>>a>>b;
cha=max(cha,a-b);// 最大差值
gongjili=max(gongjili,a);// 最大攻击力
}
if(gongjili>=m){// 特判一下
ans=;
return ;
}
if(cha<=){// 判断差值<=0
ans=-;
return ;
}
m-=gongjili;
int sum=;sum+=m/cha;
if(m%cha){
sum++;
}
ans=sum;
return ;
}
signed main(){
int _;
cin>>_;
while(_--){
cin>>n>>m;// 输入数据
ans=;
work();//
printf("%lld\n",ans);
}
return ;
}

Educational Codeforces Round 72 (Rated for Div. 2) B题的更多相关文章

  1. Educational Codeforces Round 72 (Rated for Div. 2) C题

    C. The Number Of Good Substrings Problem Description: You are given a binary string s (recall that a ...

  2. Educational Codeforces Round 72 (Rated for Div. 2) A题

    Problem Description: You play your favourite game yet another time. You chose the character you didn ...

  3. Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序

    Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序 [Problem Description] ​ 给你 ...

  4. 拓扑排序入门详解&&Educational Codeforces Round 72 (Rated for Div. 2)-----D

    https://codeforces.com/contest/1217 D:给定一个有向图,给图染色,使图中的环不只由一种颜色构成,输出每一条边的颜色 不成环的边全部用1染色 ps:最后输出需要注意, ...

  5. Educational Codeforces Round 72 (Rated for Div. 2)

    https://www.cnblogs.com/31415926535x/p/11601964.html 这场只做了前四道,,感觉学到的东西也很多,,最后两道数据结构的题没有补... A. Creat ...

  6. Coloring Edges(有向图环染色)-- Educational Codeforces Round 72 (Rated for Div. 2)

    题意:https://codeforc.es/contest/1217/problem/D 给你一个有向图,要求一个循环里不能有相同颜色的边,问你最小要几种颜色染色,怎么染色? 思路: 如果没有环,那 ...

  7. Educational Codeforces Round 72 (Rated for Div. 2) Solution

    传送门 A. Creating a Character 设读入的数据分别为 $a,b,c$ 对于一种合法的分配,设分了 $x$ 给 $a$ 那么有 $a+x>b+(c-x)$,整理得到 $x&g ...

  8. Educational Codeforces Round 72 (Rated for Div. 2)E(线段树,思维)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;#define BUF_SIZE 100000 ...

  9. Educational Codeforces Round 72 (Rated for Div. 2)C(暴力)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;char s[200007];int a[20 ...

随机推荐

  1. 串口(USART)框图的讲解

    STM32 的 USART 简介 通用同步异步收发器(Universal Synchronous Asynchronous Receiver and Transmitter)是一个串行通信设备,可以灵 ...

  2. Django dumpdata and loaddata

    目录 dumpdata 命令 dumpdata 基本数据库的转存 dumpdata 备份特定的 app dumpdata 备份特定的表 dumpdata (--exclude) dumpdata (- ...

  3. R|批量循环处理同一格式文件-csv,txt,excel

    本文首发于“生信补给站”微信公众号,https://mp.weixin.qq.com/s/8IfMrSr9xc8_1Y2_9Ne6hg 在一个文件夹下有很多字段一致,格式统一的数据文件(csv,txt ...

  4. Swiper 轮播插件 之 动态加载无法滑动

    1.原因:轮播图未完全动态加载完成,即初始化 2.方法一:ajax链式编程 $.ajax({ type: "get", url: serviceURL + "/listB ...

  5. ASP.NET全局编码和语言

    // /*--------------- // //  使用地方:ASP.NET 项目 // //   // // 文件名: // // 文件功能描述:可控制整个项目的一个统一编码格式和语言文字显示 ...

  6. C++标准库里自带的数值类型和字符串互相转换函数

    需要包含头文件 #include <string> 数值类型转成string类型: string to_string(int val); string to_string(unsigned ...

  7. element-ui重置表单并清除校验的方法

    this.$refs['activityForm'].resetFields(); 只会重置之前表单的内容,并不会清空 只需在关闭弹框的cancel方法中写上重置表单的方法即可 cancel() { ...

  8. spring 实现事务配置的方式

    spring 中常用的两种事务配置方式以及事务的传播性.隔离级别 一.注解式事务 1.注解式事务在平时的开发中使用的挺多,工作的两个公司中看到很多项目使用了这种方式,下面看看具体的配置demo. 2. ...

  9. iOS圆弧渐变进度条的实现

    由于项目需要一个环形渐变进度条显示课程,这方便网上的确有很多相关资料但是,都是比较零散的而且,大多数只是放一堆代码就算完了.这里我想详细写一篇我自己实现这个进度条的过程. 实现一个圆弧进度条主要分为三 ...

  10. 使用私有api实现自己的iphone桌面,并根据app的使用次数对app排序

    使用<iphone SprintBoard部分私有API总结>中提到的api,除了能对app运行次数进行监控以外,还可以实现自己的iphone桌面,并根据app 的使用次数对app图标进行 ...