Educational Codeforces Round 72 (Rated for Div. 2) B题
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题的更多相关文章
- 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 ...
- 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 ...
- Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序
Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序 [Problem Description] 给你 ...
- 拓扑排序入门详解&&Educational Codeforces Round 72 (Rated for Div. 2)-----D
https://codeforces.com/contest/1217 D:给定一个有向图,给图染色,使图中的环不只由一种颜色构成,输出每一条边的颜色 不成环的边全部用1染色 ps:最后输出需要注意, ...
- Educational Codeforces Round 72 (Rated for Div. 2)
https://www.cnblogs.com/31415926535x/p/11601964.html 这场只做了前四道,,感觉学到的东西也很多,,最后两道数据结构的题没有补... A. Creat ...
- Coloring Edges(有向图环染色)-- Educational Codeforces Round 72 (Rated for Div. 2)
题意:https://codeforc.es/contest/1217/problem/D 给你一个有向图,要求一个循环里不能有相同颜色的边,问你最小要几种颜色染色,怎么染色? 思路: 如果没有环,那 ...
- 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 ...
- Educational Codeforces Round 72 (Rated for Div. 2)E(线段树,思维)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;#define BUF_SIZE 100000 ...
- 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 ...
随机推荐
- 2019版UI学习路线(含大纲+视频+工具+网盘+面试题)
2019最新UI设计师教程(学习路线+课程大纲+视频教程+面试题+学习工具) 什么是全链路UI设计 UI设计师是随着网络而兴起的新兴设计行业,从事对软件的人机交互.操作逻辑.界面美观的整体设计工作.涉 ...
- SAS学习笔记40 SAS程序运行过程
当我们提交运行一个DATA步程序后,具体发生了什么事情. SAS程序与其他程序一样,在运行时都要经过两个阶段:编译(Compilation).执行(Execution) 程序首先经过编译阶段,该阶段主 ...
- 简单二次封装的Golang图像处理库:图片裁剪
简单二次封装的Golang图像处理库:图片裁剪 一.功能 Go语言下的官方图像处理库 简单封装后对jpg和png图像进行缩放/裁剪的库 二.使用说明 1.首先下载 go get -v -u githu ...
- android 项目集成 微信支付
0.环境 下载 libammsdk.jar 1.需要的常量值 public class Constant { /** 微信中用到的常量值 */ public static final class WX ...
- CAS单点登录相关配置
一.CAS单点登录服务端的部署 部署 把CAS所对应的war包部署到tomcat中 4.品优购资源V1.3\配套软件\配套软件\CAS\cas.war 配置 更改tomcat的端口号 <Conn ...
- centos 升级glibc-2.17
wget http://copr-be.cloud.fedoraproject.org/results/mosquito/myrepo-el6/epel-6-x86_64/glibc-2.17-55. ...
- [LeetCode] 283. Move Zeroes ☆(移动0到最后)
描述 给定一个数组nums,写一个函数,将数组中所有的0挪到数组的末尾,维持其他所有非0元素的相对位置. 举例: nums = [0, 1, 0, 3, 12], 函数运行后结果为[1, 3, 12, ...
- Manifold learning 流形学习
Machine Learning 虽然名字里带了 Learning 一个词,让人乍一看觉得和 Intelligence 相比不过是换了个说法而已,然而事实上这里的 Learning 的意义要朴素得多. ...
- 跨平台打开一个URL的方法
unit u_urlOpen; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System ...
- Cordova自定义插件开发
Cordova自定义插件开发 一.创建Cordova项目 在创建项目前请确保安装Cordova Cordova环境配置:https://www.w3cschool.cn/cordova/cordova ...