Codeforces 892 B.Wrath
2 seconds
256 megabytes
standard input
standard output
Hands that shed innocent blood!
There are n guilty people in a line, the i-th of them holds a claw with length Li. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the i-th person kills the j-th person if and only if j < i and j ≥ i - Li.
You are given lengths of the claws. You need to find the total number of alive people after the bell rings.
The first line contains one integer n (1 ≤ n ≤ 106) — the number of guilty people.
Second line contains n space-separated integers L1, L2, ..., Ln (0 ≤ Li ≤ 109), where Li is the length of the i-th person's claw.
Print one integer — the total number of alive people after the bell rings.
4
0 1 0 10
1
2
0 0
2
10
1 1 3 0 0 0 2 1 0 3
3
In first sample the last person kills everyone in front of him.
题目大意:n个人排队,第i个人会杀死第j个人当且仅当j < i并且j ≥i-li,问最后有多少个人能幸存下来.
分析:从后往前扫,这样就避免了j<i的干扰,记录一下i-li的最小值,就能判断第j个人是否会被杀死.
时间复杂度O(n).
#include <cstdio>
#include <cmath>
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int inf = 0x7fffffff; int n, l[], maxx = inf, ans; int main()
{
scanf("%d", &n);
for (int i = ; i <= n; i++)
scanf("%d", &l[i]);
for (int i = n; i >= ; i--)
{
if (i >= maxx)
ans++;
maxx = min(maxx, i - l[i]);
}
printf("%d\n", n - ans); return ;
}
Codeforces 892 B.Wrath的更多相关文章
- codeforces 892 - A/B/C
题目链接:https://cn.vjudge.net/problem/CodeForces-892A Jafar has n cans of cola. Each can is described b ...
- Codeforces 892 C.Pride
C. Pride time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- Codeforces 892 D.Gluttony
D. Gluttony time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- Codeforces 892 A.Greed
A. Greed time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- codeforces #446 892A Greed 892B Wrath 892C Pride 891B Gluttony
A 链接:http://codeforces.com/problemset/problem/892/A 签到 #include <iostream> #include <algor ...
- Codeforces Round #446 (Div. 2) B. Wrath【模拟/贪心】
B. Wrath time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- 【Codeforces Round #446 (Div. 2) B】Wrath
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 倒着来,维护一个最小的点就可以了. [代码] #include <bits/stdc++.h> using namesp ...
- Codeforces Round #446 (Div. 2)
Codeforces Round #446 (Div. 2) 总体:rating涨了好多,虽然有部分是靠和一些大佬(例如redbag和ShichengXiao)交流的--希望下次能自己做出来2333 ...
- CF892.B. Wrath
---恢复内容开始--- 题意: 有n个犯人,手上都有个长度为Li的武器,当铃响时大家同时挥动武器,只能把前面攻击范围内的敌人杀死,问最后还剩几个人. 题目传送门: [http://codeforce ...
随机推荐
- nginx缓存配置及开启gzip压缩
阅读目录 一:nginx缓存配置 二:nginx开启gzip 回到顶部 一:nginx缓存配置 在前一篇文章,我们理解过http缓存相关的知识点, 请看这篇文章. 今天我们来学习下使用nginx服务来 ...
- [转]List of Visual Studio Project Type GUIDs
本文转自:http://www.codeproject.com/Reference/720512/List-of-Visual-Studio-Project-Type-GUIDs There isn' ...
- 初识jstl标签库
JSTL(JSP Standard Tag Library,JSP标准标签库) 是一个不断完善的开源的 JSP 标签库,是由 apache 的 jakarta 小组来维护的,根据 JST L标签所提供 ...
- 序列化pickle模块
1.pickle模块 pickle.dumps() 和pickle.loads() import pickle f = open('112.pkl','w') a = {'name':2,2:3,3: ...
- Linux PHP的运行模式
关系图 首先聊一下服务器,常见的web server类型有apache和nginx Apache工作模式 Apache的工作模式是Apache服务器在系统启动后,预先生成多个进程副本驻留在内存中,一旦 ...
- SqlServer 2008 创建测试数据
包含要点: 数据库的循环 . insert select 句式 . 随机数(rand()函数).绝对值(abs()函数) ) ) DECLARE @randomvalue float SET @s ...
- C#创建任务计划
因写的调用DiskPart程序是要用管理员身份运行的,这样每次开机检查都弹个框出来确认肯定不行.搜了下,似乎也只是使用任务计划程序运行来绕过UAC提升权限比较靠谱,网上的都是添加到计算机启动的,不是指 ...
- 洛谷 P1618 三连击(升级版)
题目描述 将1,2,…,9共9个数分成三组,分别组成三个三位数,且使这三个三位数的比例是A:B:C,试求出所有满足条件的三个三位数,若无解,输出“No!!!”. //感谢黄小U饮品完善题意 输入输出格 ...
- Halcon学习笔记2
图像预处理 一般来说,我们采集到的图像会有一些小黑点,小斑点,不平滑等因素会会影响我们后期的算法,此时就需要我们对其图片进行预处理. 下面是一些预处理基本算子: 1.消除噪声:mean_image/b ...
- 深度剖析 MySQL 事务隔离
概述 今天主要分享下MySQL事务隔离级别的实现原理,因为只有InnoDB支持事务,所以这里的事务隔离级别是指InnoDB下的事务隔离级别. 隔离级别 读未提交:一个事务可以读取到另一个事务未提交的修 ...