Codeforces 892B Wrath(模拟)

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.

Input
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.

Output
Print one integer — the total number of alive people after the bell rings.

Example
Input
4
0 1 0 10
Output
1
Input
2
0 0
Output
2
Input
10
1 1 3 0 0 0 2 1 0 3
Output
3
Note
In first sample the last person kills everyone in front of him.

题意:

听说穿女装打acm有buff加成,但是死神达达讨厌女装,所以他要让n名女装大佬自相残杀。 一行中有n名女装大佬,每名女装大佬手中都拿着Li长度的镰刀。当12点钟声响起,每个人都会杀死在他左边的Li个人,该项动作同时进行。死神达达想知道最后存活下来的人数。

题解:

从后往前模拟即可,看代码即可。

#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1e6+5;
int a[maxn];
int main()
{
    int n;
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
            cin>>a[i];
        int ans=0;
        int k=0;
        for(int i=n-1;i>=0;i--)
        {
            if(k==0)
                ans++;
            k=max(a[i],k-1);
        }
        cout<<ans<<endl;
    }
    return 0;
}
时间: 2024-11-08 22:59:23

Codeforces 892B Wrath(模拟)的相关文章

codeforces 591B Rebranding (模拟)

Rebranding Problem Description The name of one small but proud corporation consists of n lowercase English letters. The Corporation has decided to try rebranding - an active marketing strategy, that includes a set of measures to change either the bra

Codeforces 389B(十字模拟)

Fox and Cross Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Fox Ciel has a board with n rows and n columns. So, the board consists of n × n cells. Each cell contains either a symbol '.', or a s

CodeForces 697B Barnicle 模拟

强行模拟 纪念一下…… 1 #include<stdio.h> 2 #include<iostream> 3 #include<algorithm> 4 #include<math.h> 5 #include<string.h> 6 #include<string> 7 #include<map> 8 #include<vector> 9 #include<queue> 10 #define M(a

CodeForces - 344A Magnets (模拟题)

CodeForces - 344A Magnets Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangula

CodeForces 670E(模拟双向链表)

题意:给你一串合法的括号和当前光标的位置和一些操作,问操作完之后的串是怎么样的 思路:模拟一个双向链表的操作,首先先预处理出配对的括号组,然后模拟即可 #include<bits\stdc++.h> using namespace std; const int maxn = 1e6; struct Node { int l,r; }nodes[maxn]; char s1[maxn],s2[maxn]; int a[maxn],d[maxn]; int main() { int n,m,pos

CodeForces 709B Checkpoints 模拟

题目大意:给出n个点的坐标,和你当前的坐标,求走过n-1个点的最短路程. 题目思路:走过n-1个点,为了使路程更短,那么不走的点只可能第一个点或最后一个点.模拟就行了,比较恶心. 1 #include<iostream> 2 #include<algorithm> 3 #include<cstring> 4 #include<vector> 5 #include<stdio.h> 6 #include<stdlib.h> 7 #inc

Berland National Library codeforces 567B(模拟)

http://codeforces.com/problemset/problem/567/B 题意:图书馆有一个程序,可以记录学生的进出情况,'+'表示进入,'-'表示出去,字符后面的数字表示学生的编号.在这个程序尚未启动前,还有一些同学进的消息没有被记录下来.现在问你这个图书馆至少得容纳多少学生. 分析:用sum和ans两个值来记录,sum存当前房间人数,ans维护最大值. #include <iostream> #include <stdio.h> #include <s

892B. Wrath#愤怒的连环杀人事件(cin/cout的加速)

题目出处:http://codeforces.com/problemset/problem/892/B 题目大意:一队人同时举刀捅死前面一些人后还活着几个 #include<iostream> #define IO ios::sync_with_stdio(false);\cin.tie(0);\cout.tie(0); using namespace std; typedef __int64 LL; const int maxn = 2e6+10; int p[maxn]; //库中有max

CodeForces 825B(模拟&amp;贪心_D题)解题报告

题目链接:http://codeforces.com/problemset/problem/825/B -------------------------------------------------------------------------------- 题意:五子棋,在输入条件下,能否在当前局面获胜. 思路:很明显的是,当我们下五子棋时,我们每步都是进行一次搜索,观察能否连接成为5个.同理,利用计算机也可以向各个方向进行搜索.好在本题只是10X10的棋面,直接对每个点进行4个方向(水