演算法筆記——奇技淫巧
阿新 • • 發佈:2022-05-11
目錄
大整數類
大整數類 __int128
只在基於 \(\tt Lumix\) 系統的環境下可用,38位精度,除輸入輸出外與普通資料型別無差別。
輸入輸出流定義如下:
__int128 read() { int128 x = 0; bool f = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = 1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return f ? -x : x; } void write(__int128 x) { if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar(x % 10 + '0'); }
相關例題:自測神地 - AcWing - A+B Problem,一道可以用大整數類逃課的題 - AtCoder - 250-like Number。
namespace
封裝程式碼
使用 namespace
名作為字首來區分相同名稱的函式與變數,常見於大模擬題、大暴力題。
相似於 using namespace std
,如果不加上這一句,所有的 std
函式前都需要加上 std::
,例如蔣老師的程式碼。樣例如下: