快速读入模板使用

来源:互联网 发布:golang 1.7.5安装 编辑:程序博客网 时间:2024/05/18 23:58








先上代码:

namespace IO {    const int MT = 5e7;//        额外内存占用     char buf[MT]; int c, sz;    void begin() {        c = 0;        sz = fread(buf, 1, MT, stdin);//            输入内容一次性读入     }    template<class T>    inline bool read(T &t) {//               读入转换         while(c < sz && buf[c] != '-' && (buf[c] < '0' || buf[c] > '9')) c++;        if(c >= sz) return false;//          读取完成         bool flag = 0; if(buf[c] == '-') flag = 1, c++;        for(t = 0; c < sz && '0' <= buf[c] && buf[c] <= '9'; c++) t = t * 10 + buf[c] - '0';        if(flag) t = -t;        return true;    }}
IO::begin();IO::read(n);






分析:


不得不说   快速读入确实就像开了挂一样     快的一批    今天交了cf的一个题感触颇深    





从上到下依次为


快速读入

cin   +   std::ios::sync_with_stdio(false);

scanf ();

cin



才10万数据      cin直接超时      真是呵呵了       




题目链接:http://codeforces.com/contest/892/problem/B





AC代码:

#include<bits/stdc++.h>using namespace std;namespace IO {    const int MT = 5e7;    char buf[MT]; int c, sz;    void begin() {        c = 0;        sz = fread(buf, 1, MT, stdin);    }    template<class T>    inline bool read(T &t) {        while(c < sz && buf[c] != '-' && (buf[c] < '0' || buf[c] > '9')) c++;        if(c >= sz) return false;        bool flag = 0; if(buf[c] == '-') flag = 1, c++;        for(t = 0; c < sz && '0' <= buf[c] && buf[c] <= '9'; c++) t = t * 10 + buf[c] - '0';        if(flag) t = -t;        return true;    }}int a[1000005];int main (){IO::begin();int n;while (IO::read(n)){for (int i=1;i<=n;i++) IO::read(a[i]);int temp=0x3f3f3f3f;int sum=0;for (int i=n;i>=1;i--){if (i<temp)sum++;temp=min(i-a[i],temp);}printf ("%d\n",sum); }}