首页 > 其他 > 详细

HDU 6044

时间:2017-09-27 09:40:30      阅读:208      评论:0      收藏:0      [点我收藏+]

fast IO

考虑边界情况

 

技术分享
 1 namespace IO {
 2     const int MT = 40 * 1024 * 1024;  /// 40MB 请注意输入数据的大小!!!
 3     char IO_BUF[MT];
 4     int IO_PTR, IO_SZ;
 5     /// 要记得把这一行添加到main函数第一行!!!
 6     void begin() {
 7         IO_PTR = 0;
 8         IO_SZ = fread (IO_BUF, 1, MT, stdin);
 9     }
10     template<typename T>
11     inline bool scan_d (T & t) {
12         while (IO_PTR < IO_SZ && IO_BUF[IO_PTR] != - && (IO_BUF[IO_PTR] < 0 || IO_BUF[IO_PTR] > 9))
13             IO_PTR ++;
14         if (IO_PTR >= IO_SZ) return false;
15         bool sgn = false;
16         if (IO_BUF[IO_PTR] == -) sgn = true, IO_PTR ++;
17         for (t = 0; IO_PTR < IO_SZ && 0 <= IO_BUF[IO_PTR] && IO_BUF[IO_PTR] <= 9; IO_PTR ++)
18             t = t * 10 + IO_BUF[IO_PTR] - 0;
19         if (sgn) t = -t;
20         return true;
21     }
22     inline bool scan_s (char s[]) {
23         while (IO_PTR < IO_SZ && (IO_BUF[IO_PTR] ==   || IO_BUF[IO_PTR] == \n) ) IO_PTR ++;
24         if (IO_PTR >= IO_SZ) return false;
25         int len = 0;
26         while (IO_PTR < IO_SZ && IO_BUF[IO_PTR] !=   && IO_BUF[IO_PTR] != \n)
27             s[len ++] = IO_BUF[IO_PTR], IO_PTR ++;
28         s[len] = \0;
29         return true;
30     }
31     template<typename T>
32     void print(T x) {
33         static char s[33], *s1; s1 = s;
34         if (!x) *s1++ = 0;
35         if (x < 0) putchar(-), x = -x;
36         while(x) *s1++ = (x % 10 + 0), x /= 10;
37         while(s1-- != s) putchar(*s1);
38     }
39     template<typename T>
40     void println(T x) {
41         print(x); putchar(\n);
42     }
43 };
View Code

 

HDU 6044

原文:http://www.cnblogs.com/skyette/p/7599811.html

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