首页 > 其他 > 详细

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

时间:2017-12-17 14:50:18      阅读:244      评论:0      收藏:0      [点我收藏+]

题目出处: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同名 
int main(){
    IO;//输入输出流加速
    int n;cin>>n;
    for(int i=0;i<n;i++) cin>>p[i];
    LL cnt=p[n-1], ans=1;
    for(int i=n-2; i>=0; i--){
        if(!cnt) ans++;
        cnt = (cnt-1)>p[i]?(cnt-1):p[i];
    } 
    cout<<ans<<endl;
    return 0;
}

本题题目解题思路并不难,但是在测试的时候多次超时,然后看了别人的代码,在此体现了cin/cout的慢节奏

解决办法就是加入两行代码

#define IO ios::sync_with_stdio(false);\cin.tie(0);\cout.tie(0);
IO;//输入输出流加速
详细原因百度都可以查到。

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

原文:http://www.cnblogs.com/hello-OK/p/8051918.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!