链接:

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;
}

最新文章

  1. [PHP]Maximum execution time of 30 seconds exceeded
  2. 浏览器Range,Selection等选中文本对象
  3. 当padding,margin,top为百分比值,具体数值如何计算
  4. js生成二维码(jquery自带)
  5. 使用MiniProfiler调试ASP.NET MVC网站性能
  6. Android中获取图片的宽和高
  7. linux rpm 安装包 信息查询
  8. 用Jquery控制文本框只能输入数字和字母
  9. 程序调试手段之gdb, vxworks shell
  10. ios项目开发(天气预报项目):通过经纬度获取当前城市名称
  11. Oracle 数据库用户管理
  12. java安全HTTPS工具类
  13. Java集合源代码剖析(二)【HashMap、Hashtable】
  14. 【Android 应用开发】Android 开发错误集锦
  15. .net core ef 通过dbfirst方式连接mysql数据库
  16. c语言第三次课
  17. Python----unittest discover()方法与执行顺序
  18. IE浏览器下flex布局的bug
  19. 关于Asset Library核心功能的一些计划
  20. java 的三种代理

热门文章

  1. 转载:微信开放平台开发第三方授权登陆(二):PC网页端
  2. matplotlib笔记1
  3. Java中数据存储分配
  4. scratch少儿编程——03、动作:运动的开始,游戏的基础。
  5. (二)shiro之jsp标签
  6. Swiper 轮播插件 之 动态加载无法滑动
  7. MarkDown 语法记录
  8. solr-jd
  9. 关闭google默认打开翻译提醒
  10. layer弹出层移动端组件