退役小贴士

1、离散化写一次挂一次

	cin>>n;
	for(int i=1;i<=n;i++){
		a[i]=read();b[i]=read();
		o[++ont]=a[i];o[++ont]=b[i];
	}
	sort(o+1,o+1+ont);
	int ok=unique(o+1,o+1+ont)-o;
	for(int i=1;i<=n;i++){
		a[i]=lower_bound(o+1,o+1+ok,a[i])-o-1;
		b[i]=lower_bound(o+1,o+1+ok,b[i])-o-1;
	}

但是这是错的!!!

正确代码:

	cin>>n;
	for(int i=1;i<=n;i++){
		a[i]=read();b[i]=read();
		o[++ont]=a[i];o[++ont]=b[i];
	}
	sort(o+1,o+1+ont);
	int ok=unique(o+1,o+1+ont)-o-1;//这里!!!要减一!!!
	for(int i=1;i<=n;i++){
		a[i]=lower_bound(o+1,o+1+ok,a[i])-o;//这里!!
		b[i]=lower_bound(o+1,o+1+ok,b[i])-o;//没有减一!!
	}

2、小数“-0.000”

这得特判……

3、万恶的Dinic

3.1、bfs的时候……

d[ss]=0;

但是会shi循环

应该是:

d[ss]=1;

3.2、建图的时候……

tot=1

忘了加这个,调了一年……

3.3、加边的时候……

void adde(int u,int v,int w){
	tot++;
	e[tot].nxt=head[u];
	e[tot].to=v;
	e[tot].w=w;
}

又 挂 了 一 年 。 。 。 。 。

void adde(int u,int v,int w){
	tot++;
	e[tot].nxt=head[u];
	e[tot].to=v;
	e[tot].w=w;
	head[u]=tot;//真想不通怎么忘了这个的
}

4、数论

关于数论:最难的地方是式子,最坑的地方是取模和括号。

关于取模:希望不要手残把模数抄错,比如说 \(1e7+19\)

5、运算优先级

运算符的优先级可能是最高的…………

也可能是最低的

所以每逢就加括号就完事…………

6、检查

可以在代码中加些注释以示提醒…………

放到最后检查基本上就只能看看 freopen 之类的……

考场上可能不容易看出来的点:模意义下的分数……

7、long long

很容易爆。。。(尤其是数论题)。。。

尽量用减法或及时break。

8、全局变量

全局:int n;

main内:int n=read();

函数内:for(int i=1;i<=n;i++)

然后:???我的 n 怎么是 0 ???

9、字符串输入

不要用getchar !!!
不要用getchar !!!
不要用getchar !!!

你不知道题目是否给了换行符。
你也不知道题目中是否有空行。
你甚至不知道 if(ch==0) 有什么道理。

所以 "cin + 指针" 也许更加稳妥 。
然后你就 TLE 了

再一次:不要用getchar!!!
再一次:不要用getchar!!!
再一次:不要用getchar!!!

即使是while(ch==' ')ch=getchar();也不要!!!
不知道是什么奇奇怪怪的问题。总之再也不用getchar了。

10、树剖

	while(top[u]!=top[v]){
		if(d[top[u]]<d[top[v]])swap(u,v);
		//写成了d[u]<d[v]
		upd(rt,dfn[top[u]],dfn[u]);
		u=fa[top[u]];
	}
	if(d[u]>d[v])swap(u,v);
	upd(rt,dfn[u]+1,dfn[v]);

11、二维映射一维

我以前是这么写的:

inline int g(int x,int y){
	return (x-1)*m+y;
}

但是如果涉及了:mp[g(i-1,j)]
就会 \(RE\) 掉。。。(会有负数)

然后改成了这样,但是需要开大数组:

inline int g(int x,int y){
	return (m+1)*x+y+1;
}
posted @ 2021-08-17 20:19  大不美列坚  阅读(78)  评论(0)    收藏  举报