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 $ 找到一种方案,使得操作数最少. 解法: ...
随机推荐
- MySQL学习之SQL基础(一)DML
DML(data Manipulation language) INSERT DELETE UPDATE SELECT INSERT mysql> desc emp; +----------+- ...
- Unix-Time
1. Unix_time 2. Year_2000_problem 3. Year_10,000_problem 4. Year_2038_problem 5. Time_formatting_and ...
- Spark 下操作 HBase(1.0.0 新 API)
hbase1.0.0版本提供了一些让人激动的功能,并且,在不牺牲稳定性的前提下,引入了新的API.虽然 1.0.0 兼容旧版本的 API,不过还是应该尽早地来熟悉下新版API.并且了解下如何与当下正红 ...
- 矿难已经过去,NVIDIA将高举光追大旗!
在去年8月推出支持光线追踪技术的Turing图灵GPU之前,显卡市场差不多沉沦了两年,很大一个原因就是2017到2018年初的数字货币市场爆发,矿卡市场取代了游戏卡市场成为增长点,那一年多显卡厂商的日 ...
- TX2开发板Ubuntu16.04设置静态IP
TX2开发板Ubuntu16.04设置静态IP https://www.cnblogs.com/qilai/p/11285445.html 首先打开一个Terminal输入 ifconfig 查看自 ...
- C++学习链表
#include"pch.h" #include<iostream> #include<string> using namespace std; struc ...
- Python 列表/元组/字典总结
序列是Python中最基本的数据结构.序列中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0,第二个索引是1,依此类推. Python有6个序列的内置类型,但最常见的是列表和元组. 序列 ...
- 【WPF学习】第二十四章 基于范围的控件
WPF提供了三个使用范围概念的控件.这些控件使用在特定最小值和最大值之间的数值.这些控件——ScrollBar.ProgressBar以及Slider——都继承自RangeBase类(该类又继承自Co ...
- Emacs服务器模式以及emacsclient配置
Emacs有很多强大的插件,但是插件安装多了会导致启动速度很慢.为了解决这个问题,一个方法是使用emacs提供的server模式. 基本用法[1] 启动emacs server: $ emacs -- ...
- vuejs+thinkphp5+phpsocketIO+timer数据及时更新
1.安装thinkphp5.0以上版本包含workerman框架2.composer安装composer require workerman/phpsocket.io3.vue中调用需要加载weapp ...