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. RecursiveSequence(HDU-5950)【矩阵快速幂】

    题目链接: 题意:Si=S(i-1)+2*S(i-2)+i^4,求Sn. 思路:想到了矩阵快速幂,实在没想出来怎么构造矩阵.... 首先构造一个向量vec={a,b,16,8,4,2,1}. 在构造求 ...

  2. Python列表排序方法reverse、sort、sorted详解

    python语言中的列表排序方法有三个:reverse反转/倒序排序.sort正序排序.sorted可以获取排序后的列表.在更高级列表排序中,后两中方法还可以加入条件参数进行排序. reverse() ...

  3. python学习-45 模块

    模块 -----模块包括三种: ····python标准库 ····第三方模块 ····应用程序自定义模块 -------应用程序自定义模块 1.建立两个py文件,一个是定义函数用的cal.py de ...

  4. 1262: 谁不爱打牌(Java)

    WUSTOJ 1262: 谁不爱打牌 转自 断-肠-人的博客 Java代码在文末 Description BobLee最近在复习考研,但是他也喜欢打牌(有谁不爱玩牌呢?).但是作为一名ACMER,斗地 ...

  5. 怎样在网页中嵌入JS代码

    有四种方法: 方法1: 在<script>标签内直接写代码 <body> <button id="btn">click</button&g ...

  6. 字符串的简单操作----记录次数 hdu2617

    统计出字符串中共能拼凑出多少happy.happy相对次序不变. #include<cstdio> #include<iostream> #include<string. ...

  7. 轻松搭建CAS 5.x系列(5)-增加密码找回和密码修改功能

    概述说明 CAS内置了密码找回和密码修改的功能: 密码找回功能是,系统会吧密码重置的连接通过邮件或短信方式发送给用户,用户点击链接后就可以重置密码,cas还支持预留密码重置的问题,只有回答对了,才可以 ...

  8. Node初始以及环境搭建(Node01)

    1. 相关概念 •什么是JavaScript? •一种遵守ECMAScript标准的脚本语言 •最初只能运行在浏览器端 •浏览器中的 JavaScript 可以做什么? •操作DOM:表单验证.动画 ...

  9. HelenOS

    HelenOS 来源 http://www.helenos.org/ 关于HELENOS HelenOS是一种基于便携式微内核的多服务器操作系统,从头开始设计和实现.它将关键操作系统功能(如文件系统, ...

  10. Citrix ADC 12.1 / NetScaler 12

    Citrix ADC 12.1 / NetScaler 12 参考 https://www.carlstalhood.com/netscaler-menu/netscaler-12/ Core – C ...