跳到正文

个人记录

注意事项

面条小王子约 4 分钟
原文
文章信息与版本

文章信息

发布
2025年10月29日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 4 分钟

版本

  1. v3当前
  2. v2
  3. v1

2026.11.1

INF 的数不要太大(除非你特判严格)

否则加几个数就溢出

long long MAX = 0x7fffffffffffffff

INF 可以设 0x7f7f7f7f7f7f7f7f

他们相差 0x0080808080808080 即 36170086419038336

2026.10.29

整数除法是向 0 取整

例如 −1/2=0-1 / 2 = 0

并且 floor ceil 函数要内部是double才可以正确处理

例如 floor(−1/2)=0,floor(−1.0/2)=−1floor(-1 / 2) = 0, floor(-1.0 / 2) = -1

2026.10.26

字符 op∈[′0′,′9′]op \in ['0', '9'] 转换成编号 OP∈[0,9]OP \in [0, 9],可以 OP=(op⊕′0′)OP = (op \oplus '0')

但 大写字母 和 小写字母不行

本质上 48 = 110000

发现 0~9 二进制只有 4 位异或不影响

2026.9.29

快速幂 10 mod 1=01^0 \bmod 1 = 0 !!!

2026.7.12

交互题一定要换行

2026.7.6

当你写下

C++
void f()
{
	static int cnt = 0;
}

多次调用函数 f,cnt不会清空

C++
void f()
{
	static int cnt;
	cnt = 0;
}

这样才可以

2026-4-10

哈希函数

C++
for (register int i = 1; i <= len; ++ i) powB[i] = 1ll * powB[i - 1] * B % P, H[i] = (1ll * H[i - 1] * B % P + str[i] - 'a') % P;

上式子是错的

str[i] - 'a' 不能为 0

如果为0, aa 和 ajaj 会相同

2025-11-15

函数是要有返回值的

2025-10-29

关于set/map存结构体

重载运算符写完整

这段代码输出 11

C++
struct node
{
	int cnt, id;
	bool operator< (const node &t)const
	{
		return cnt > t.cnt;
	}
};
set<node> tong;

int main()
{
	tong.insert({1, 5});
	tong.insert({1, 6});
	cout << tong.size();
	return 0;
}

这段代码输出 22

C++
struct node
{
	int cnt, id;
	bool operator< (const node &t)const
	{
		if (cnt == t.cnt) return id > t.id;
		return cnt > t.cnt;
	}
};
set<node> tong;

int main()
{
	tong.insert({1, 5});
	tong.insert({1, 6});
	cout << tong.size();
	return 0;
}

这段代码输出 11

C++
struct node
{
	int cnt, id;
	bool operator< (const node &t)const
	{
		return cnt > t.cnt;
	}
};
map<node, int> tong;

int main()
{
	tong[{1, 5}] = 1;
	cout << tong[{1, 6}];
	return 0;
}

这段代码输出 00

C++
struct node
{
	int cnt, id;
	bool operator< (const node &t)const
	{
		if (cnt == t.cnt) return id > t.id;
		return cnt > t.cnt;
	}
};
map<node, int> tong;

int main()
{
	tong[{1, 5}] = 1;
	cout << tong[{1, 6}];
	return 0;
}
原文