1. 程式人生 > >892B. Wrath#憤怒的連環殺人事件(cin/cout的加速)

892B. Wrath#憤怒的連環殺人事件(cin/cout的加速)

style max com 輸入輸出流 name 詳細 百度 sync 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同名 
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的加速)