读入优化? fread ??? NAIVE !!! streambuf -- sgetn
来源:互联网 发布:四知太守杨震 编辑:程序博客网 时间:2024/06/05 06:09
大家都很强, 可与之共勉 。
比fread快的读入优化
使用底层的streambuf, 用rdbuf ( )获取。
# include <cctype># include <cstdio># include <iostream>inline int read ( ) {# define SIZE 1000005 static std :: streambuf *fb ( std :: cin.rdbuf ( ) ) ; static char buf [SIZE], *ss ( 0 ), *tt ( 0 ) ;# define pick( ) ( (ss == tt) ? ( tt = buf + fb -> sgetn ( ss = buf, SIZE ), ((ss == tt) ? -1 : *(ss ++)) ) :*(ss ++) ) register int x, c ; bool opt ( 1 ) ; while ( ! isdigit ( c = pick ( ) ) && ( c ^ -1 ) && ( c ^ 45 ) ) ; if ( c == 45 ) c = pick ( ), opt = 0 ; for ( x = -48 + c ; isdigit ( c = pick ( ) ) ; ( x *= 10 ) += c - 48 ) ; return opt ? x : -x ;}int main ( ) { std :: ios :: sync_with_stdio ( 0 ) ; std :: cin.tie ( 0 ) ; int s ( 0 ) ; int n ( read ( ) ) ; while ( n -- ) s ^= read ( ) ; printf ( "%d\n", s ) ;}
阅读全文
1 0
- 读入优化? fread ??? NAIVE !!! streambuf -- sgetn
- fread 读入优化
- fread读入优化,寻找速度极限
- 更快的读入优化fread
- 读入输出优化 黑科技 快过fread&&fwite
- fread 读入挂模板
- fread 快速读入
- streambuf
- seerc2013 C 关于fread读入
- 读入优化
- 读入优化
- 读入优化
- 读入优化
- 读入优化
- 读入优化
- 读入优化
- 读入优化
- 读入优化
- GPS定位基本原理浅析
- java中for循环删除元素的问题
- C语言 三角形 的判断
- Java课程学习四:编程题
- 欧几里德&&扩展欧几里德
- 读入优化? fread ??? NAIVE !!! streambuf -- sgetn
- nodejs 中的 bcrypt (1) : bcrypt 的特点与应用
- gitlab经过nginx代理后,项目地址显示ip
- RxJava 2.0(一)
- Linux 常用命令 scp, 7z
- Ealsticsearch 5.x 遇到的坑
- 了解机器视觉
- SpringBoot中Session超时原理说明
- Color the ball(线段树)