标签:stat get getc prot word 优化 eof long turn
/* 快速乘法 */ #include <cstdio> #include <iostream> void read (long long &now) { register char word = getchar (); for (now = 0; !isdigit (word); word = getchar ()); for (; isdigit (word); ) { now = (now << 1) + (now << 3) + word - ‘0‘; word = getchar (); } } long long Mod = 10000; struct Mul { protected : long long x; public : long long operator * (Mul now) const { long long res = 0, pos = this->x; pos = pos % Mod; now.x = now.x % Mod; for (; now.x; now.x >>= 1) { if (now.x & 1) res = (res + pos) % Mod; pos = (pos + pos) % Mod; } return res; } public : long long operator = (const int &now) { x = now; } }; Mul A, B; int main () { long long a, b; read (a); read (b); A = a; B = b; printf ("%lld", A * B); }
/* O(1)快速乘 */ #include <cstdio> long long Mod = 100; struct Int { long long x; long long operator * (Int now) const { long long res = (this->x * now.x - (long long)((long long)this->x / Mod * now.x + 1.0e-8) * Mod); return res < 0 ? res + Mod : res; } }; int main () { Int a, b; a.x = 200; b.x = 3; printf ("%lld", a * b); }
/* IO读入优化 */ #include <iostream> #include <cstdio> /* void read (int &now) { register char word = getchar (); for (now = 0; !std :: isdigit (word); word = getchar ()); for (; std :: isdigit (word); now = now * 10 + word - ‘0‘, word = getchar ()); }*/ inline char getcha () { static char buf[100000], *pos_1 = buf, *pos_2 = buf; return pos_1 == pos_2 && (pos_2 = (pos_1 = buf) + fread (buf, 1, 100000, stdin), pos_1 == pos_2) ? EOF : *pos_1 ++; } inline int read (int &now) { register char word = getcha (); for (now = 0; !std :: isdigit (word); word = getcha ()); for (; isdigit (word); now = now * 10 + word - ‘0‘, word = getcha ()); } int main (int argc, char *argv[]) { freopen ("1.in", "r", stdin); int N; read (N); read (N); read (N); printf ("%d", N); return 0; }
标签:stat get getc prot word 优化 eof long turn
原文地址:http://www.cnblogs.com/ZlycerQan/p/7309231.html