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 ...
随机推荐
- python3 字符集的应用
python3的字符集测试 s_test=u"严" print(s_test.encode('gbk')) print([s_test]) #print(s_test[]) #pr ...
- 探索grafana
因为zabbix的监控图形不够美观,功能也不够强大, 那么就用到了grafana 填写zabbix插件配置: 如下需要根据主机群组和主机名来完成图形: grafana报警如下: 解决如下: 更改标准设 ...
- 网络模式: host-only & NAT & 桥接
基本上,Host-only相当于虚拟机和宿主机通过交叉线相连:NAT,宿主机相当于虚拟机的路由器:桥接,相当于把宿主机和虚拟机同时接到交换机上,然后交换机接到外网. 连接性上说,可参考下表: 连接 宿 ...
- react-router 5.0 的鉴权
react-router 5.0 的鉴权 当我们使用react-router 控制页面的路由时候,有些页面,是需要登录才能访问,有些不需要登录就可以访问,还有些页面,是根据用户的权限来限制访问的. 如 ...
- PAT-1003 Emergency (25 分) 最短路最大点权+求相同cost最短路的数量
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
- (六)springmvc之ModelAndView、Model、Map、ModelMap
<a href="<%=request.getContextPath()%>/responseData/response_1">使用原生的作用域</a ...
- (八)二进制文件在webservice中的处理(以byte[]字节数组方式)
一.介绍 二进制文件在webservice中的处理. A:通过byte[]字节数组的方式来传递.比较适合小文件,字节数组不能太大的情况.(本章所用) B:通过DataHander的方式来进行传递. 1 ...
- 基于Docker的Kafka部署
一 准备 1.1 安装docker-dompose #部署 sudo curl -L "https://github.com/docker/compose/releases/download ...
- ligerui tab 部分记载
打开一个Tab $(".strength_box").click(function () { var id = $(this).attr("data"); va ...
- EDK2开发环境搭建
EDK2开发环境搭建 来源 https://blog.csdn.net/rikeyone/article/details/80759724 EDK2全称为“uEFI Development Kit”, ...