赛时可以用到的小技巧

  • 很好用的小技巧,用于检测全局变量的静态使用空间和程序实际耗时
#include<bits/stdc++.h>
#define int long long
using namespace std;
bool M1; // 最前面
const int N=1e6+10 ,M=1e5;
int a[N] ;
bool M2; //最后面
signed main() {
	cerr<<"used time = "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n";
	cerr<<"used memory = "<<abs(&M1-&M2)/1024/1024<<"MB\n";
	return 0;
}
  • 记不到从哪里整过来的快读快写了,
namespace IO{
	const static int _M=1e6+5,_K=2e6+5;
	char ibuf[_K],obuf[_K],_st[_K],*p1(0),*p2(0);
	static int _cnt=0,_top=0;
	inline void flush(){return fwrite(obuf,1,_cnt,stdout),_cnt=0,void();}
	struct AutoFlush{~AutoFlush(){flush();}}flusher;
	inline char gc(){return (p1==p2&&(p2=(p1=ibuf)+fread(ibuf,1,_K,stdin),p1==p2)?EOF:*p1++);}
	template<typename T>inline void read(T&x){
		x=0;char c;bool f=0;
		do{c=gc();if(c=='-') f=1;}while(c<48);do{x=(x<<3)+(x<<1)+(c^48);c=gc();}while(c>=48);
		return(f?x=~x+1,void():void()),void();
	}
	template<typename T>inline void readmod(T&x,int mod){
		x=0;char c;
		do{c=gc();}while(c<48);do{x=((x<<3)+(x<<1)+(c^48))%mod;c=gc();}while(c>=48);
		return;
	}
	inline void pc(char c){obuf[_cnt++]=c;if(_cnt>=_M)flush();return;}
	inline void ps(string s){for(auto c:s)obuf[_cnt++]=c;if(_cnt>=_M)flush();return;}
	template<typename T>inline void write(T x,char c='\0'){
		if(x<0) pc('-'),x=-x;
		do{_st[++_top]=(x%10)|48;}while(x/=10);while(_top)pc(_st[_top--]);
		return(c?pc(c):void()),void();
	}
}
using namespace IO;
  • 一个萌萌拍子
#include <bits/stdc++.h> 
#define int long long
using namespace std ;

void resetIO() {
#ifdef _WIN64
	freopen("CON","r",stdin) ;
	freopen("CON","w",stdout) ;
#endif
}
int Random(int mod) {
	int ans=998244;
	return ans*rand()%mod+1 ;
}
void make_date() {
	ofstream in ("in.txt") ;
	const int N=1e6 ; //数据范围 
	int n=Random(N) ,m=Random(N);
	in<<n<<" "<<m<<endl ;
//	for(int i=1;i<=n;i++) in<<Random(A)<<" " ;
	in.close() ;
}
int n,m; 
void std_solve() {
	ifstream cin("in.txt") ;
	ofstream cout("std.txt") ;
	cin>>n>>m ;
	int ans=0 ;
	for(int i=1;i<=n+m;i++) ans+=2 ;
	cout<<ans ;
	resetIO() ;
}
void my_sovle() {
	ifstream cin("in.txt") ;
	ofstream cout("my.txt") ;
	cin>>n>>m ;
	cout<<(n+m)*2 ;
	resetIO() ;
}
bool check() {
	string a,b; 
	ifstream f1("std.txt"),f2("my.txt") ;
	while(f1>>a&&f2>>b) if(a!=b) return 0 ;
	return 1 ;
}

signed main() {
//	ios::sync_with_stdio(0); cin.tie(0) ; cout.tie(0) ;
	int tot=0 ;
	while(1) {
		make_date() ;std_solve() ; my_sovle() ;
		if(check()) cout<<"Accept on "<<++tot<<"\n" ;
		else {
			cout<<"!!! WA !!!\n" ;
			cout<<n<<" "<<m<<"\n" ;
			system("pause") ;
			exit(0) ;
		}
	}
	return 0; 
}

posted @ 2026-07-20 19:29  Emumumu  阅读(14)  评论(0)    收藏  举报