\[\Huge\color{#F48DAE}\text{《你 永 远 不 知 道 你 的 锅 会 出 在 哪 里》} \]
- 想清楚,再下手写代码
- 用二分查找错误
- 要静态查找,如果有相似的地方可以对比着查
- 尽量不要用补全,自己手写
- 不要复制代码
- 当变量较多,且意义相似时,尽量使用明确的变量名
- 至少读三遍题
- 不要用 memeset
- 精度要设
1e-8
- 写长式子要用换行和空格使他更直观得看到每个部分的意义和差异
- 遇到读字符就有可能是输入的问题,要造个很多空格的样例测输入
- 要多加括号
- 二分时 l 设 0,r 设 \(10^9\)
- Floyd 的初始化
f[i][i]
要设为 0 - 尽量不要用double
- 不要混用
i++
和++i
// luogu id : 361726
#include <bits/stdc++.h>
using namespace std;
// #define lbt(x) (x & -x)
// #define rs(x) ((x << 1) | 1)
// #define ls(x) (x << 1)
// #define Set_Mid int mid = ((l + r) >> 1)
// #define fson 1, n, 1
// #define lson l, mid, ls(k)
// #define rson mid + 1, r, rs(k)
// #define lk(k) ((k - 1) * len + 1)
// #define uk(k) ((k - 1) * len)
// #define rk(k) (k * len)
// #define jk(k) ((k + len - 1) / len)
#define pii pair<int, int>
#define fr first
#define se second
#define pbk push_back
#define mpr make_pair
#define ll long long
#define ull unsigned long long
#define umap unordered_map
#define db double
#define re return
#define con continue
#define brk break
#define il inline
#define big(a, b) (a = max(a, b))
#define sml(a, b) (a = min(a, b))
#define FO(i, n) for (int i = 1; i <= (n); i ++)
#define OF(i, n) for (int i = (n); i >= 1; i ++)
#define FOR(i, j, n) for (int i = (j); i <= (n); i ++)
#define REP(i, j, a) for (int i = (j); (a); i ++)
#define ROF(i, j, n) for (int i = (j); i >= (n); i --)
#define PER(i, j, a) for (int i = (j); (a); i --)
inline void SR(){}
template <class SR_Type, class... SR_Types> inline void SR(SR_Type &x, SR_Types&... y){int f=1;x=0;char c=getchar();for(;!isdigit(c);c=getchar())if(c=='-')f=-1;for(;isdigit(c);c=getchar())x=x*10+(c^48);x*=f;SR(y...);}
inline void SC(){}
template <class SC_Type, class... SC_Types> inline void SC(SC_Type &x, SC_Types&... y){x=getchar();for(;x<33||x>126;x=getchar());SC(y...);}
inline void SS(){}
template <class SS_Type, class... SS_Types> inline void SS(SS_Type &x, SS_Types&... y){x="";char c=getchar();for(;c<33||c>126;c=getchar());for(;!(c<33||c>126);c=getchar())x=x+c;SS(y...);}
inline void GS(){}
template <class GS_Type, class... GS_Types> inline void GS(GS_Type &x, GS_Types&... y){x="";char c=getchar();for(;c<33||c>126;c=getchar());for(;c!='\n';c=getchar())x=x+c;GS(y...);}
template <class prk_Type> inline void pk(prk_Type x){cout<<x;printf(" ");return;}
// #define pk(y) (233) //!!!
const char l1 = '|';
#define err() cout<<"err "<<__LINE__<<"\n",exit(0)
#define p(args...) \
GPT(#args),cout<<" Line "<<__LINE__<<"\t: ", \
PPT(args),cout<<"\n\n"
#define pa(x,args...) \
GPT(#x),cout<<" Line "<<__LINE__<<"\t: ", \
PPT(args),cout<<"\n\n"
#define po(x, l, r) \
GPT(#x),cout<<" Line "<<__LINE__<<"\t: ", \
PRY(x, l, r)
void PPT(){}
template<typename PPT_Type,typename... PPT_Types>
void PPT(const PPT_Type& x,const PPT_Types&... y){
cout<<x<<' ';
PPT(y...);
}
template<typename PRY_Type> void PRY(PRY_Type *a,int l,int r){cout << l << " " << r << ": ";FOR(i,l,r) cout<<*(a+i)<<' ';printf("\n\n");}
void GPT(string nam){cout<<setw(29)<<nam;}
ll seed=chrono::system_clock::now().time_since_epoch().count();
mt19937 rnd(seed);
// const int fx[] = {0, 0, 1, -1};
// const int fy[] = {1, -1, 0, 0};
// const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
// const int dy[] = {1, -1, 0, 0, -1, 1, -1, 1};
const int N = 1e6 + 233;
const int M = 3e4 + 233;
const int BS = rnd() % 2333 + 6;
const int b = rnd() % 233;
const int p = 1000249;
il int Hash(char s[]) {
int val = 0;
int len = strlen(s + 1);
FOR(i, 1, len) {
val = ((val * BS) + s[i] + b + p) % p;
}
re val;
}
struct Edge {
int now, to, nxt;
}e[M];
int hd[N], en;
il void adde(int now, int to) {
e[++ en].now = now;
e[en].to = to;
e[en].nxt = hd[now];
hd[now] = en;
re;
}
int stk[N], sn;
int dfn[N], low[N], dn;
int fa[N], fn;
int ary[N], bry[N];
int n, m;
il void dfs(int now) {
dn ++;
dfn[now] = dn;
low[now] = dn;
stk[++ sn] = now;
for (int i = hd[now], to; i; i = e[i].nxt) {
to = e[i].to;
if (!dfn[to]) {
dfs(to);
sml(low[now], low[to]);
}
else if (!fa[to]) {
sml(low[now], low[to]);
}
}
if (dfn[now] == low[now]) {
int tmp = 0;
fn ++;
while (tmp != now) {
tmp = stk[sn --];
fa[tmp] = fn;
}
}
re;
}
char x[23], y[23];
signed main() {
SR(n);
FO(i, n) {
scanf("%s%s", x + 1, y + 1);
ary[i] = Hash(x);
bry[i] = Hash(y);
adde(ary[i], bry[i]);
}
SR(m);
FO(i, m) {
scanf("%s%s", x + 1, y + 1);
adde(Hash(y), Hash(x));
}
FO(i, n) {
if (!dfn[ary[i]]) {
dfs(ary[i]);
}
if (!dfn[bry[i]]) {
dfs(bry[i]);
}
}
FO(i, n) {
if (fa[ary[i]] == fa[bry[i]]) {
printf("Unsafe\n");
}
else {
printf("Safe\n");
}
}
return 0;
}
标签:经验,检查,int,void,Code,inline,define,Type,getchar
From: https://www.cnblogs.com/MJawa/p/17641392.html