版本比较
.zip全新力作!工具大全。
正文
增加 66 行删除 32 行
10 行未改动11121314151617181920326 行未改动全部展开347348349350349351352353354355407 行未改动全部展开7637647657667657677687697707717727737747757767777787797807817827837847857867877887897907917927937947 行未改动80280380480579580680780880981081181281380381481581681781880881982082182282382482581582682782882983098 行未改动9299309319329229339349359369379279389399409419329429439449459369469479489499409509519529539542 行未改动957958959960951961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011163 行未改动全部展开117511761177117811311132113311341135113611371138113911401141114211431144114511461147117911801181118245 行未改动12281229123012311232123312341235123612371238175 行未改动全部展开141414151416141713841418141914201421142214231424142513921426142714281429139614301431143210 行未改动想了又想,改了无数个新式,最终确定以头文件的形式表现出来。
你现在看见的,只不过是一个蒟蒻的脑洞大开,如有不足,可以指明更正;如果你不喜欢,就当看个乐子。
【26/11/20】正在尝试进行 linux 适配,目前可在 linux 环境下进行编译,但功能不全。
# 食用说明
这是头文件的介绍,当然您也可以在头文件中看到:
326 行未改动全部展开### real 生成随机实数
1. 使用 `real(1,r,precision,RandGen)` 生成在区间 $[l,r]$ 的随机实数,分度值为 `precision` 默认 $1000$,`RandGen` 同上。
关于精度值:关于分度值:
- 并不是小数点后几位,而是将区间 $[l,r]$ 分成 `precision` 份,每次随机取一个分界线。
```cpp407 行未改动全部展开#define DUIPAI#ifdef DUIPAI
#include<bits/stdc++.h>#include<windows.h>using namespace std;
typedef unsigned long long ull;typedef long long ll;
#ifdef _WIN32/*--------------------------Windowes--------------------------------*/
#include<windows.h>
namespace behavior{ //行为 bool pause=0; //是否在结束之前暂停 bool log=0; //是否输出日志 bool process=0; //是否输出进程 string compile="-std=c++14 -O2"; //编译命令 string chcp="65001"; ofstream logout("tls.log",ios::app);}
void Start(){ system(("chcp "+behavior::chcp+" > nul").c_str()); //将控制台编码改为utf-8}
void addlog(string s,string t){ //写入日志/输出进程 if(behavior::process&&t!="") std::cout<<t<<endl; if(!behavior::log||s=="") return; SYSTEMTIME T;7 行未改动#define _RED 12#define _YELLOW 14#define _PURPLE 13
void printc(string s, int color=7){ //带颜色的输出void printc(string s, int color=7){//带颜色的输出 HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | color); addlog("output: "+s+" with color "+to_string(color),""); std::cout<<s; SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | 7);}
void end(int exitnum){ //退出程序void end(int exitnum){//退出程序 addlog("Program exited with code "+to_string(exitnum),"程序退出,退出码 "+to_string(exitnum)); exit(exitnum);}
void exitcode(int exitnum,string s=""){ //退出程序并输出void exitcode(int exitnum,string s=""){//退出程序并输出 if(exitnum==-1) printc("错误 ",12); if(s!="") std::cout<<s<<'\n'; if(behavior::pause) system("pause"); end(exitnum);}
namespace RunSpace{ //子进程运行空间namespace RunSpace{//子进程运行空间 string name,argv; clock_t st=0,ed=0; int returned=0; DWORD WINAPI TestedProgram(LPVOID lpParameter){98 行未改动 bool TLE(){return res==_TLE;}; bool WA(){return res==_WA;};};
LUNCHRES Lunch(int timlim,vector<string> argvs){ //启动一次对拍,timlim:时间限制;argvs 对于每一个程序的命令行参数。LUNCHRES Lunch(int timlim,vector<string> argvs){//启动一次对拍,timlim:时间限制;argvs 对于每一个程序的命令行参数。 if(argvs.size()!=4) exitcode(-1,"参数串数不匹配,请传入恰好 4 个参数串");
ResSpace::RES res,tmpres;
tmpres=gen.Run(-1,argvs[0]);//运行生成器 if(tmpres.waitres!=0) exitcode(-1,"数据生成器 "+RunSpace::name+" 运行失败"); if(tmpres.prores!=0) exitcode(-1,"数据生成器 "+RunSpace::name+" 的返回值不为零:"+to_string(tmpres.prores));
tmpres=cur.Run(timlim,argvs[3]); //运行正确程序 tmpres=cur.Run(timlim,argvs[3]);//运行正确程序 if(tmpres.waitres==WAIT_TIMEOUT) exitcode(-1,"程序 "+RunSpace::name+"运行超时"); if(tmpres.prores) exitcode(-1,"程序 "+RunSpace::name+" 的返回值不为零:"+to_string(tmpres.prores));
res=tst.Run(timlim,argvs[2]); //运行待测程序 res=tst.Run(timlim,argvs[2]);//运行待测程序 if(res.waitres==WAIT_TIMEOUT) return {_TLE,0,0}; if(res.prores) return {_RE,res.prores,res.runtime};
tmpres=chk.Run(-1,argvs[1]); //运行答案校验器 tmpres=chk.Run(-1,argvs[1]);//运行答案校验器 if(tmpres.waitres!=0) exitcode(-1,"答案校验器 "+RunSpace::name+" 运行失败"); if(tmpres.prores!=_WA&&tmpres.prores!=_PE&&tmpres.prores!=_AC){ exitcode(-1,"无法识别答案校验器的返回值:"+to_string(tmpres.prores)); }2 行未改动
return {_WA,res.prores,res.runtime};}
void judgment(LUNCHRES res){ //判断对拍结果void judgment(LUNCHRES res){//判断对拍结果 if(res.AC()) printc("AC ",_GREEN); if(res.WA()) printc("WA ",_RED); if(res.TLE()) printc("TLE ",_PURPLE); if(res.RE()) printc("RE "+to_string(res.returned)+' ',_YELLOW); std::cout<<(double)res.runtime/CLOCKS_PER_SEC<<" s"<<endl; if(!res.AC()) exitcode(1,"对拍出现错误,程序退出。");}#endif/*--------------------------\Windowes--------------------------------*/
#ifdef __linux__/*--------------------------linux--------------------------------*/
#include<time.h>
namespace behavior{ //行为 bool log=0; //是否输出日志 bool process=0; //是否输出进程 string compile="-std=c++14 -O2"; //编译命令 ofstream logout("tls.log",ios::app);}
void addlog(string s){ if(!behavior::log) return; time_t timer=time(NULL); struct tm *T=localtime(&timer); behavior::logout<<T->tm_year+1900<<'/'<<T->tm_mon+1<<'/'<<T->tm_mday<<' '; behavior::logout<<T->tm_hour<<':'<<T->tm_min<<':'<<T->tm_sec<<' '; behavior::logout<<s<<'\n';}void addpro(string s){ if(!behavior::process) return; cout<<s<<'\n';}
void exitcode(int exitnum,string exitinfo){ if(exitinfo!=""){ if(exitnum==-1) cout<<"\033[31m错误\033[0m "; if(exitnum==-2) cout<<"\033[31m警告\033[0m "; cout<<exitinfo<<'\n'; } exit(exitnum);}
#endif/*--------------------------\linux--------------------------------*/
class RandGen{//随机数生成器 ull key1=0x1234567890abcdefull; ull key2=0xabcdef1234567890ull; void shift1(){163 行未改动全部展开 for(T i:y) x.push_back(i); return x;}
ofstream ouf;
void InitGen(int argc,char* argv[]){ if(argc<3) exitcode(-1,"参数过少,按照以下方式传参:<种子> <生成文件>");
RandFunc::_rand.seed(argv[1]); ouf.open(argv[2]);
if(!ouf.is_open()) exitcode(-1,(string)"无法输出到文件:"+argv[2]);
addlog("The generator is ready!","生成器准备完成!");}
void Start(){ system(("chcp "+behavior::chcp+" > nul").c_str()); //将控制台编码改为utf-8}
//输出相关
struct OutputStyle{ string start;45 行未改动}template<typename T>OutputPointer<multiset<T>> pack(multiset<T> v,OutputStyle s={"{",", ","}"}){ return OutputPointer<multiset<T>>{v,s};}template<typename T1,typename T2>OutputMapPointer<map<T1,T2>> pack(map<T1,T2> v,OutputStyle s){ return OutputMapPointer<map<T1,T2>>{v,map_s};}template<typename T1,typename T2>OutputMapPointer<map<T1,T2>> pack(map<T1,T2> v,OutPutMapStyle s={"{",{"[",", ","]"},": ",{"(",", ",")"},", ","}"}){ return OutputMapPointer<map<T1,T2>>{v,s};}template<typename T1,typename T2>OutputMapPointer<multimap<T1,T2>> pack(multimap<T1,T2> v,OutPutMapStyle s={"{",{"[",", ","]"},": ",{"(",", ",")"},", ","}"}){175 行未改动全部展开
```:::
## 后记# 后记
终于写完了……吗?
显然这是个半成品。
我会不定时更新,欢迎大家提出建议。
## AI 使用说明:# AI 使用说明:
仅使用 DeepSeek 检查头文件中的 UB 行为。
## 版权说明:# 版权说明:
这个头文件是蒟蒻自己敲出来的,转载请说明来源,感谢各位大佬的支持。