CodeForces - 892B(栈操作)

本文提供了一段关于ACM竞赛中算法题目的解决方案,通过使用栈来解决特定问题,介绍了如何进行有效的时间复杂度控制,并提供了完整的代码实现。

Wrath

题目传送门

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 10000000
using namespace std;
typedef long long ll;
const int MAXN=5e6+10;
const int MAX=1e6+10;
const double eps=1e-6;



int main(){
    #ifdef ONLINE_JUDGE
    #else
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    #endif

    int n,t,ans=0;
    cin>>n;
    stack<int>q;
    q.push(1);
    for(int i=1;i<=n;i++){
        scanf("%d",&t);
        if(i==1)    continue;
        else{
            while(q.size()&&(q.top()-(i-t))>=0)
                q.pop(),ans++;
            q.push(i);
        }
    }
    cout<<n-ans<<endl;

    return 0;   
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值