快读快写

快读

inline int read()
{
	int s=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9') {s=s*10+(ch^48);ch=getchar();}
	return s*f;
}

快写

inline void write(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}

但是由于递归的常数巨大

所以我们可以采用栈来输出

注:static 表示该全局变量在程序一开始运行便创立,不会每次输出重开浪费空间,但是其赋予初值也只在创建的时候赋一次,所以要另外赋予其初始值。

但是我们一般不用快写,用得不舒服。

如:

//wrong
void dfs(){
	static int a=0;
}
//right
void dfs(){
	static int a;
	a=0;
}

最终版本

这样我们读入不需分辨类型了。

template<class T>
inline void read(T &s){
	s=0;char ch=getchar();bool f=0;
	while(ch<'0'||'9'<ch) {if(ch=='-') f=1;ch=getchar();}
	while('0'<=ch&&ch<='9') {s=s*10+(ch^48);ch=getchar();}
	if(ch=='.'){
		int p=10;ch=getchar();
		while('0'<=ch&&ch<='9') {s=s+(db)(ch^48)/p;p*=10;;ch=getchar();};
	}
	s=f?-s:s;
}
inline void write(int x){
	if(x<0) x=-x,putchar('-');
	static char Wstack[20],top;top=0;
	do{Wstack[top]=x-x/10*10;x/=10;++top;}while(x);
	while(top){putchar(Wstack[--top]+'0');}
}

后来我们发现了叫做 freadfwrite 的东西。

fread(a,b,c,d) 表示从d中读入c份大小为byte的字符置入a中。

fwrite同理。

记得初始化。

inline int read()
{
	int s=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9') {s=s*10+(ch^48);ch=getchar();}
	return s*f;
}
inline void write(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}

但是由于递归的常数巨大

所以我们可以采用栈来输出

注:static 表示该全局变量在程序一开始运行便创立,不会每次输出重开浪费空间,但是其赋予初值也只在创建的时候赋一次,所以要另外赋予其初始值。

但是我们一般不用快写,用得不舒服。

如:

//wrong
void dfs(){
	static int a=0;
}
//right
void dfs(){
	static int a;
	a=0;
}

最终版本

这样我们读入不需分辨类型了。

template<class T>
inline void read(T &s){
	s=0;char ch=getchar();bool f=0;
	while(ch<'0'||'9'<ch) {if(ch=='-') f=1;ch=getchar();}
	while('0'<=ch&&ch<='9') {s=s*10+(ch^48);ch=getchar();}
	if(ch=='.'){
		int p=10;ch=getchar();
		while('0'<=ch&&ch<='9') {s=s+(db)(ch^48)/p;p*=10;;ch=getchar();};
	}
	s=f?-s:s;
}
inline void write(int x){
	if(x<0) x=-x,putchar('-');
	static char Wstack[20],top;top=0;
	do{Wstack[top]=x-x/10*10;x/=10;++top;}while(x);
	while(top){putchar(Wstack[--top]+'0');}
}

后来我们发现了叫做 freadfwrite 的东西。

fread(a,b,c,d) 表示从d中读入c份大小为byte的字符置入a中。

fwrite同理。

记得初始化。

#include<bits/stdc++.h>
#define ll long long
#define db double
#define filein(a) freopen(#a".in","r",stdin)
#define fileot(a) freopen(#a".out","w",stdout)
#define sky fflush(stdout);
#define gc getchar
#define pc putchar
#define Better_IO true
namespace IO{
	#if Better_IO==true
		char buf[(1<<20)+3],*p1(buf),*p2(buf);
		char buf2[(1<<20)+3],*p3(buf2);
		const int lim=1<<20;
		inline char gc(){
			if(p1==p2) p2=(p1=buf)+fread(buf,1,lim,stdin);
			return p1==p2?EOF:*p1++;
		}
		#define pc putchar
	#else
		#define gc getchar
		#define pc putchar
	#endif
	inline bool blank(const char &c){
		return c==' ' or c=='\n' or c=='\t' or c=='\r' or c==EOF;
	}
	inline void gs(char *s){
		char ch=gc();
		while(blank(ch) ) {ch=gc();}
		while(!blank(ch) ) {*s++=ch;ch=gc();}
		*s=0;
	}
	inline void gs(std::string &s){
		char ch=gc();s+='#';
		while(blank(ch) ) {ch=gc();}
		while(!blank(ch) ) {s+=ch;ch=gc();}
	}
	inline void ps(char *s){
		while(*s!=0) pc(*s++);
	}
	inline void ps(const std::string &s){
		for(auto it:s) 
			if(it!='#') pc(it);
	}
	template<class T>
	inline void read(T &s){
		s=0;char ch=gc();bool f=0;
		while(ch<'0'||'9'<ch) {if(ch=='-') f=1;ch=gc();}
		while('0'<=ch&&ch<='9') {s=s*10+(ch^48);ch=gc();}
		if(ch=='.'){
			db p=0.1;ch=gc();
			while('0'<=ch&&ch<='9') {s=s+p*(ch^48);p*=0.1;ch=gc();}
		}
		s=f?-s:s;
	}
	template<class T,class ...A>
	inline void read(T &s,A &...a){
		read(s);read(a...);
	}
};
using IO::read;
using IO::gs;
using IO::ps;
int main(){
	filein(a);fileot(a);

	return 0;
}

posted @   cbdsopa  阅读(53)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示