首页 > 其他分享 >Code时如何检查&检查经验

Code时如何检查&检查经验

时间:2023-08-18 19:12:06浏览次数:24  
标签:经验 检查 int void Code inline define Type getchar

\[\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

相关文章

  • Codeforces Round 881 (Div. 3)
    比赛链接:https://codeforces.com/contest/1843A.SashaandArrayColoring题意:一个数组,可以任意分成任意组,每组的贡献是组最大值减最小值,求最大总贡献思路:一组内只有最大值和最小值有用,所以每组只由两个数组成即可,用贪心的思路,依次取出原数组的最大和最小值成组即可B.LongL......
  • vscode主题配置
    配置{"cSpell.languageSettings":[],"editor.bracketPairColorization.enabled":true,"editor.guides.bracketPairs":"active","files.autoSave":"afterDelay","workbench.iconThe......
  • 图片上传生成缩略图相关code
    记录一下以前的code(现在看起来当时的代码是这么写出来的,哈哈,自嘲一下),可以结合minio等obs文件服务器//在ASP.NET中上传图片并生成缩略图//检查上传文件的格式是否有效if(this.fileupload.PostedFile.ContentType.ToLower().IndexOf("image")......
  • [LeetCode][70]climbing-stairs
    ContentYouareclimbingastaircase.Ittakesnstepstoreachthetop.Eachtimeyoucaneitherclimb1or2steps.Inhowmanydistinctwayscanyouclimbtothetop? Example1:Input:n=2Output:2Explanation:Therearetwowaystoclimbtothet......
  • [LeetCode][62]unique-paths
    ContentThereisarobotonanmxngrid.Therobotisinitiallylocatedatthetop-leftcorner(i.e.,grid[0][0]).Therobottriestomovetothebottom-rightcorner(i.e.,grid[m-1][n-1]).Therobotcanonlymoveeitherdownorrightatanypointi......
  • [LeetCode][64]minimum-path-sum
    ContentGivenamxngridfilledwithnon-negativenumbers,findapathfromtoplefttobottomright,whichminimizesthesumofallnumbersalongitspath.Note:Youcanonlymoveeitherdownorrightatanypointintime. Example1:Input:grid=[[......
  • [LeetCode][55]jump-game
    ContentYouaregivenanintegerarraynums.Youareinitiallypositionedatthearray'sfirstindex,andeachelementinthearrayrepresentsyourmaximumjumplengthatthatposition.Returntrueifyoucanreachthelastindex,orfalseotherwise.......
  • [LeetCode][32]longest-valid-parentheses
    ContentGivenastringcontainingjustthecharacters'('and')',returnthelengthofthelongestvalid(well-formed)parenthesessubstring. Example1:Input:s="(()"Output:2Explanation:Thelongestvalidparentheses......
  • [LeetCode][53]maximum-subarray
    ContentGivenanintegerarraynums,findthesubarraywiththelargestsum,andreturnitssum. Example1:Input:nums=[-2,1,-3,4,-1,2,1,-5,4]Output:6Explanation:Thesubarray[4,-1,2,1]hasthelargestsum6.Example2:Input:nums=[1]Output:......
  • [LeetCode][10]regular-expression-matching
    ContentGivenaninputstrings andapatternp,implementregularexpressionmatchingwithsupportfor'.'and'*'where:'.'Matchesanysinglecharacter.​​​​'*'Matcheszeroormoreoftheprecedingelement.T......