[关闭]
@Dmaxiya 2023-03-11T19:38:15.000000Z 字数 1546 阅读 935

零碎知识点

板子


离散化

  1. // T 类型在 unique 函数中需重载 == 运算符
  2. // 在 lower_bound 函数中需重载 < 运算符
  3. struct T {};
  4. bool operator<(const T &a, const T &b);
  5. bool operator==(const T &a, const T &b);
  6. vector<T> sand;
  7. sand.clear();
  8. sort(sand.begin(), sand.end());
  9. sand.erase(unique(sand.begin(), sand.end()), sand.end());
  10. x = lower_bound(sand.begin(), sand.end(), T()) - sand.begin();

输出 __int128

  1. ostream& operator<<(ostream &out, LL x) {
  2. if (x == 0) {
  3. return out << "0";
  4. }
  5. if(x < 0) {
  6. out << "-";
  7. x = -x;
  8. }
  9. static int sta[100];
  10. int top = 0;
  11. memset(sta, 0, sizeof(sta));
  12. while(x != 0) {
  13. sta[top++] = x % 10;
  14. x /= 10;
  15. }
  16. for(int i = top - 1; i >= 0; --i) {
  17. out << sta[i];
  18. }
  19. return out;
  20. }

bitset 用法

函数 功能
b.any() b 中是否存在1
b.count() b 中1的个数
b.size() b 的二进制位个数
b[pos] b 在pos 处的二进制位(从低到高)
b.reset() b 的所有二进制位都置零
b.to_ulong() 返回b 的unsigned long 值
~b b 按位取反
b1 | b2 按位或
b1 & b2 按位与
b << n (b >> n) b 按位左移(右移)n位

Pólya定理:


n 表示能够循环的个数,m表示需要涂色的点的数量,一般情况下,

Lindstrom Gessel Vienot lemma 定理

对于一张给定的 图,给定 个起点和 个终点,如果从起点 到终点 的路径数为 ,则从任意一个起点到任意一个终点的两条路径不相交的方案数为行列式:


的值。

分割字符串

  1. void split(string str, string spacer, vector<string> &ret) {
  2. int pos1, pos2;
  3. int len = spacer.length();
  4. pos1 = 0;
  5. pos2 = str.find(spacer);
  6. while (pos2 != string::npos) {
  7. ret.push_back(str.substr(pos1, pos2 - pos1));
  8. pos1 = pos2 + len;
  9. pos2 = str.find(spacer, pos1);
  10. }
  11. if (pos1 != str.length()) {
  12. ret.push_back(str.substr(pos1));
  13. }
  14. }

int 转 string

  1. string intToString(LL x) {
  2. string str;
  3. if (x == 0) {
  4. return "0";
  5. }
  6. while (x != 0) {
  7. str.push_back(x % 10 + '0');
  8. x /= 10;
  9. }
  10. return reverse(str.begin(), str.end());
  11. return str;
  12. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注