1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
| #define dIO_USE_BUFFER struct IO { #ifdef dIO_USE_BUFFER const static int BUFSIZE = 1 << 20; char ibuf[BUFSIZE], obuf[BUFSIZE], *p1, *p2, *pp; inline int getchar() { return (p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, BUFSIZE, stdin), p1 == p2) ? EOF : *p1++); } inline int putchar(char x) { return ((pp - obuf == BUFSIZE && (fwrite(obuf, 1, BUFSIZE, stdout), pp = obuf)), *pp = x, pp++), x; } inline IO &flush() { return fwrite(obuf, 1, pp - obuf, stdout), pp = obuf, fflush(stdout), *this; } IO() { p1 = p2 = ibuf, pp = obuf; } ~IO() { flush(); } #else int (*getchar)() = &::getchar; int (*putchar)(int) = &::putchar; inline IO &flush() { return fflush(stdout), *this; } #endif string _sep = " "; int k = 2; template <typename Tp, typename enable_if<is_integral<Tp>::value || is_same<Tp, __int128_t>::value>::type * = nullptr> inline int read(Tp &s) { int f = 1, ch = getchar(); s = 0; while (!isdigit(ch) && ch != EOF) f = (ch == '-' ? -1 : 1), ch = getchar(); if (ch == EOF) return false; while (ch == '0') ch = getchar(); while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar(); s *= f; return true; } template <typename Tp, typename enable_if<is_floating_point<Tp>::value>::type * = nullptr> inline int read(Tp &s) { int f = 1, ch = getchar(); s = 0; while (!isdigit(ch) && ch != '.' && ch != EOF) f = (ch == '-' ? -1 : 1), ch = getchar(); if (ch == EOF) return false; while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar(); if (ch == '.') { Tp eps = 0.1; ch = getchar(); while (isdigit(ch)) s = s + (ch ^ 48) * eps, ch = getchar(), eps /= 10; } s *= f; return true; } inline int read(char &ch) { ch = getchar(); while (isspace(ch) && ch != EOF) ch = getchar(); return ch != EOF; } inline int read(char *c) { char ch = getchar(), *s = c; while (isspace(ch) && ch != EOF) ch = getchar(); while (!isspace(ch) && ch != EOF) *(c++) = ch, ch = getchar(); *c = '\0'; return s != c; } inline int read(string &s) { s.clear(); char ch = getchar(); while (isspace(ch) && ch != EOF) ch = getchar(); while (!isspace(ch) && ch != EOF) s += ch, ch = getchar(); return s.size() > 0; } template <typename Tp = int> inline Tp read() { Tp x; read(x); return x; } template <typename Tp, typename... Ts> inline int read(Tp &x, Ts &...val) { return read(x) && read(val...); } inline int getline(char *c, const char &ed = '\n') { char ch = getchar(), *s = c; while (ch != ed && ch != EOF) *(c++) = ch, ch = getchar(); *c = '\0'; return s != c; } inline int getline(string &s, const char &ed = '\n') { s.clear(); char ch = getchar(); while (ch != ed && ch != EOF) s += ch, ch = getchar(); return s.size() > 0; } template <typename Tp, typename enable_if<is_integral<Tp>::value || is_same<Tp, __int128_t>::value>::type * = nullptr> inline IO &write(Tp x) { if (x < 0) putchar('-'), x = -x; static char sta[41]; int top = 0; do sta[top++] = x % 10 ^ 48, x /= 10; while (x); while (top) putchar(sta[--top]); return *this; } inline IO &write(const string &str) { for (char ch : str) putchar(ch); return *this; } inline IO &write(const char *str) { while (*str != '\0') putchar(*(str++)); return *this; } inline IO &write(char *str) { return write((const char *)str); } inline IO &write(const char &ch) { return putchar(ch), *this; } template <typename Tp, typename enable_if<is_floating_point<Tp>::value>::type * = nullptr> inline IO &write(Tp x) { if (x > 1e18 || x < -1e18) { write("[Floating point overflow]"); throw; } if (x < 0) putchar('-'), x = -x; const static long long pow10[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000, 1000000000000, 10000000000000, 100000000000000, 1000000000000000, 10000000000000000, 100000000000000000, 100000000000000000, 100000000000000000}; const auto &n = pow10[k]; long long whole = x; double tmp = (x - whole) * n; long long frac = tmp; double diff = tmp - frac; if (diff > 0.5) { ++frac; if (frac >= n) frac = 0, ++whole; } else if (diff == 0.5 && ((frac == 0U) || (frac & 1U))) ++frac; write(whole); if (k == 0U) { diff = x - whole; if ((!(diff < 0.5) || (diff > 0.5)) && (whole & 1)) ++whole; } else { putchar('.'); static char sta[21]; int count = k, top = 0; while (frac) { sta[top++] = frac % 10 ^ 48; frac /= 10, count--; } while (count--) putchar('0'); while (top) putchar(sta[--top]); } return *this; } template <typename Tp, typename... Ts> inline IO &write(Tp x, Ts... val) { return write(x), write(_sep), write(val...), *this; } template <typename... Ts> inline IO &writeln(Ts... val) { return write(val...), putchar('\n'), *this; } template <typename... Ts> inline IO &writesp(Ts... val) { return write(val...), putchar(' '), *this; } inline IO &writeln(void) { return putchar('\n'), *this; } inline IO &sep(const string &s = " ") { return _sep = s, *this; } inline IO &prec(const int &K = 2) { return k = K, *this; } } io;
|