链接:

https://codeforces.com/contest/1238/problem/B

题意:

Ivan plays an old action game called Heretic. He's stuck on one of the final levels of this game, so he needs some help with killing the monsters.

The main part of the level is a large corridor (so large and narrow that it can be represented as an infinite coordinate line). The corridor is divided into two parts; let's assume that the point x=0 is where these parts meet.

The right part of the corridor is filled with n monsters — for each monster, its initial coordinate xi is given (and since all monsters are in the right part, every xi is positive).

The left part of the corridor is filled with crusher traps. If some monster enters the left part of the corridor or the origin (so, its current coordinate becomes less than or equal to 0), it gets instantly killed by a trap.

The main weapon Ivan uses to kill the monsters is the Phoenix Rod. It can launch a missile that explodes upon impact, obliterating every monster caught in the explosion and throwing all other monsters away from the epicenter. Formally, suppose that Ivan launches a missile so that it explodes in the point c. Then every monster is either killed by explosion or pushed away. Let some monster's current coordinate be y, then:

if c=y, then the monster is killed;

if y<c, then the monster is pushed r units to the left, so its current coordinate becomes y−r;

if y>c, then the monster is pushed r units to the right, so its current coordinate becomes y+r.

Ivan is going to kill the monsters as follows: choose some integer point d and launch a missile into that point, then wait until it explodes and all the monsters which are pushed to the left part of the corridor are killed by crusher traps, then, if at least one monster is still alive, choose another integer point (probably the one that was already used) and launch a missile there, and so on.

What is the minimum number of missiles Ivan has to launch in order to kill all of the monsters? You may assume that every time Ivan fires the Phoenix Rod, he chooses the impact point optimally.

You have to answer q independent queries.

思路:

模拟, 记录往右移的总长度.挨个判断.

代码:

#include<bits/stdc++.h>
using namespace std; set<int> St;
int n, r; int main()
{
int t;
cin >> t;
while (t--)
{
St.clear();
cin >> n >> r;
int v;
for (int i = 0; i < n; i++)
{
cin >> v;
St.insert(v);
}
int cnt = 0, sum = 0;
while (!St.empty())
{
while (!St.empty() && *St.begin()-sum <= 0)
St.erase(*St.begin()); if (St.empty())
break;
cnt++, sum += r;
St.erase(*St.rbegin());
}
cout << cnt << endl;
} return 0;
}

Educational Codeforces Round 74 (Rated for Div. 2) B. Kill 'Em All的更多相关文章

  1. Educational Codeforces Round 74 (Rated for Div. 2) D. AB-string

    链接: https://codeforces.com/contest/1238/problem/D 题意: The string t1t2-tk is good if each letter of t ...

  2. Educational Codeforces Round 74 (Rated for Div. 2) C. Standard Free2play

    链接: https://codeforces.com/contest/1238/problem/C 题意: You are playing a game where your character sh ...

  3. Educational Codeforces Round 74 (Rated for Div. 2) A. Prime Subtraction

    链接: https://codeforces.com/contest/1238/problem/A 题意: You are given two integers x and y (it is guar ...

  4. Educational Codeforces Round 74 (Rated for Div. 2)

    传送门 A. Prime Subtraction 判断一下是否相差为\(1\)即可. B. Kill 'Em All 随便搞搞. C. Standard Free2play 题意: 现在有一个高度为\ ...

  5. Educational Codeforces Round 74 (Rated for Div. 2)【A,B,C【贪心】,D【正难则反的思想】】

    A. Prime Subtractiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inpu ...

  6. Educational Codeforces Round 74 (Rated for Div. 2)补题

    慢慢来. 题目册 题目 A B C D E F G 状态 √ √ √ √ × ∅ ∅ //√,×,∅ 想法 A. Prime Subtraction res tp A 题意:给定\(x,y(x> ...

  7. Educational Codeforces Round 74 (Rated for Div. 2)E(状压DP,降低一个m复杂度做法含有集合思维)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;char s[100005];int pos[ ...

  8. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  9. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

随机推荐

  1. Redis 常用命令学四:有序集合类型命令

    1.增加元素,修改存在元素的分数 127.0.0.1:6379> zadd score 99 a 88 b 66 c (integer) 3 127.0.0.1:6379> ZADD sc ...

  2. java源码 --List、Set、Collection

    List和Set都是接口,它们继承与Collection.List是有序的队列,可以用重复的元素:而Set是数学概念中的集合,不能有重复的元素.List和Set都有它们各自的实现类. 为了方便,我们抽 ...

  3. Spring Boot系列教程十四:Spring boot同时支持HTTP和HTTPS

    自签证书 openssl生成服务端证书,不使用CA证书直接生成 -in server.csr -signkey server.key -out server.crt # 5.server证书转换成ke ...

  4. msql 数据类型

    1.数据类型 #1. 数字: 整型:tinyinit int bigint 小数: float :在位数比较短的情况下不精准 double :在位数比较长的情况下不精准 0.0000012301231 ...

  5. re 模块与正则表达式

    目录 re 模块 re 模块的基本使用 re 模块 正则表达式与re模块的关系 1:正则表达式是一门独立的技术. 2:正则在任何语言中均可以使用. 3:python中要想使用正则表达式需要通过re模块 ...

  6. spring cloud微服务实践四

    spring cloud的hystrix还有一个配搭的库hystrix-dashboard,它是hystrix的一款监控工具,能直观的显示hystrix响应信息,请求成功率等.但是hystrix-da ...

  7. WinRAR 去广告的姿势

    一直在使用WinRAR解压文件,感觉非常的好用,可是现在WinRAR添加了广告,每次打开压缩包都会弹出广告,有时候甚至在解压的时候弹出来,而每次弹出广告都会卡顿一下,忍了很长时间今天实在是受够了,准备 ...

  8. 【转载】springboot启动报错(Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWe)

    SpringBoot启动时的异常信息如下: 1 "C:\Program Files\Java\jdk1.8.0_161\bin\java" ......... com.fangxi ...

  9. restTemplate源码解析(三)创建ClientHttpRequest请求对象

    所有文章 https://www.cnblogs.com/lay2017/p/11740855.html 正文 上一篇文章中,我们大体看了一下restTemplate的核心逻辑.再回顾一下核心代码 p ...

  10. css3flex布局实现商品列表

    首先看图 手机商场经常会有商品列表功能,这样其实可以用flex布局实现 注意两个地方: 1.商品列表平衡间距(flex布局的换行加两端对齐) 2.中间文字行数不一样,会出现下方留下空白,如何解决(fl ...