CF1217B Zmei Gorynich
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 h_i 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=10d=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 tt independent queries.
The first line contains one integer t (1≤t≤100) – the number of queries.
The first line of each query contains two integers nn and x (1≤n≤100, 1≤x≤10^9) — the number of possible types of blows and the number of heads Zmei initially has, respectively.
The following nn lines of each query contain the descriptions of types of blows you can deal. The ii-th line contains two integers d_i and h_i (1≤d_i,h_i≤109) — the description of the i-th blow.
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.
3
3 10
6 3
8 2
1 4
4 10
4 1
3 2
2 6
1 100
2 15
10 11
14 100
2
3
-1
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行每行输入两个整数d-i和h_i。分别是一回合能造成的damage和造成伤害后怪物回复的hp,怪物总hp是x点。
思路是贪心,先选出一个最大的max_d_i判断与x的关系,在对d_i-h_i排个序,<0则一定有解。
下面给出代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct ss
{
long long a;
long long b;
}e[];
inline bool cmp(const ss&A,const ss&B)
{
return A.a>B.a;
}
int main()
{
int t;
scanf("%d",&t);
for(int i=;i<=t;++i)
{
ll n,m;
cin>>n>>m;
ll mmax=;
for(int j=;j<n;++j)
{
long long x,y;
cin>>x>>y;
e[j].a=x-y;
e[j].b=x;
mmax=max(mmax,x);
}
sort(e,e+n,cmp);
m-=mmax;
if(m<=)
{
cout<<<<endl;continue;
}
if(e[].a>)
{
int tt=m/e[].a+;
if(m%e[].a==)
{
tt--;
}
cout<<tt<<endl;
}
else
{
cout<<-<<endl;
}
}
return ;
}
做这题时混用了scanf和cin,为了加速关闭了文件流同步,最后就疯狂RE,切忌偷懒啊。
CF1217B Zmei Gorynich的更多相关文章
- Educational Codeforces Round 72 (Rated for Div. 2)
https://www.cnblogs.com/31415926535x/p/11601964.html 这场只做了前四道,,感觉学到的东西也很多,,最后两道数据结构的题没有补... A. Creat ...
- Educational Codeforces Round 72
目录 Contest Info Solutions A. Creating a Character B. Zmei Gorynich C. The Number Of Good Substrings ...
- Educational Codeforces Round 72 (Rated for Div. 2) B题
Problem Description: You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a ...
- 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 ...
- CF1217B
CF1217B 题意: 有一个有 $ x $ 个头的龙,你有 $ n $ 种方案,每种方案中包含你可以砍掉的头 $ d_i $ 和龙会生长的头 $ h_i $ 找到一种方案,使得操作数最少. 解法: ...
随机推荐
- java.io.FileNotFoundException: rmi_keystore.jks (No such file or directory)(转)
Caused by: java.io.FileNotFoundException: rmi_keystore.jks (没有那个文件或目录) 解决方法:修改jmeter.properites: ser ...
- vSphere中Storage vMotion的流程详解
内容预览: 1. Storage vMotion的迁移方式 2. 影响Storage vMotion效率的因素 3. Storage vMotion的详细流程 企业部署虚拟化后,如果发现存储的性能出现 ...
- springboot启动不能加载数据库驱动Failed to determine a suitable driver class
SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/G:/sharp/repo ...
- R 《回归分析与线性统计模型》page121,4.4
rm(list = ls()) A = read.xlsx("xiti_4.xlsx",sheet = 4) names(A) = c("ord"," ...
- 刷题21. Merge Two Sorted Lists
一.题目说明 这个题目是21. Merge Two Sorted Lists,归并2个已排序的列表.难度是Easy! 二.我的解答 既然是简单的题目,应该一次搞定.确实1次就搞定了,但是性能太差: R ...
- Java集合基于JDK1.8的LinkedList源码分析
上篇我们分析了ArrayList的底层实现,知道了ArrayList底层是基于数组实现的,因此具有查找修改快而插入删除慢的特点.本篇介绍的LinkedList是List接口的另一种实现,它的底层是基于 ...
- 春运到了,带你用python来抢票回家!
不知不觉,一年一度的春运抢票大幕已经拉开,想快速抢到回家的车票吗?作为程序员,这些技术手段,你一定要知道. 为了让大家更快捷更便利的抢火车票,各种各样的抢票软件应需而生,这类软件大部分都是付费抢票的机 ...
- 007-PHP变量和函数相互转换
<?php function write($text) //定义function write()函数 { print($text); //打印字符串 } function writeBold($ ...
- SpringBoot-配置Java方式
SpringBoot中使用Java方式配置步骤如下: 在类上加入@Configuration注解,代表作为配置类 在该类方法上加入@Bean注解,代表将方法返回的Bean加入Spring容器 在该类中 ...
- MQTT 协议学习:005-发布消息 与 对应报文 (PUBLISH、PUBACK、PUBREC、PUBREL)
背景 当有订阅者订阅了有关的主题以后,通过发布消息的消息的动作,可以让订阅者收到对应主题的消息. 根据不同的QoS 等级,通信的动作也略有不同. PUBLISH – 发布消息 报文 PUBLISH控制 ...