准备CSP 复赛

用来方便自己复习

版本C++14

快读和快输

链接:

打的时候一定要注意运算符优先级QWQ(有时候真的很难发现)

错误示例:

int read()
{
	static int x,f;
	static char ch;
	x=f=0;
	while(!isdigit(ch=getchar()) ) if(ch=='-') f=!f;
	while(isdigit(ch)) x=(x<<3)+(x<<1)+ch&15,ch=getchar();
	if(!f) return x;
	else return -x;
}

原因: 加法的优先级高于按位与……

正常代码:

const int L=1<<20;
char buf[L],*p1=buf,*p2=buf;
#define getchar() (p1==p2 && (p2=(p1=buf)+fread(buf,1,L,stdin),p1==p2)?EOF:*p1++)

int read()
{
	static int x,f;
	static char ch;
	x=f=0;
	while(!isdigit(ch=getchar()) ) if(ch=='-') f=!f;
	while(isdigit(ch)) x=x*10+(ch&15),ch=getchar();
	if(!f) return x;
	else return -x;
}

小数据(\(n\le 10^3\))还是scanf快点

注意事项

链接:

缺省源

//减少码量的
#define rep(i,st,n) for(int i=(st);i<=(n);++i)
#define _rep(i,st,n) for(int i=(st);i<(n);++i)
#define dwh(i,st,n) for(int i=(st);i>=(n);--i)
#define _dwh(i,st,n) for(int i=(st);i>(n);--i)

//快读快输...
//...

//还是想cin的
#define FAST_IO ios::sync_with_stdio(0),cin.tie(0)

//max() and min()
int max(int x,int y){return x>y?x:y;}
int min(int x,int y){return x<y?x:y;}
int bmax(int &x,int y){return x=max(x,y);}
int bmin(int &x,int y){return x=min(x,y);}

对拍

程序

编译器选项

链接:

编译器选项加入:

-Wl,--stack=536870912 -std=c++14 -lm -Wall

解释:

  • -Wl, 可用于查找一些编译器编译时无法查出的问题,如scanf("%d",a)
  • -Wl,--stack=SIZE 把栈的空间限制为SIZE byte(536870912 byte=512MB)
  • -std=c++14 按照c++14的标准编译
  • -Wall 打开"显示最多警告信息"
posted @ 2024-10-22 22:21  AC-13-13  阅读(1)  评论(0编辑  收藏  举报