跳到正文

剪贴板

剪贴板 6mvgvpbi

原文
剪贴板信息

剪贴板信息

收录
更新

实用工具:

置顶(OI 比赛也能用)

安全的随机数:mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

请不要用 time(0)。


1.计时工具

C++
void test()
{
    DWORD t1,t2;
    t1 = GetTickCount();
    foo();//dosomething
    t2 = GetTickCount();
    printf("Use Time:%f\n",(t2-t1)*1.0/1000);
}

来源:https://blog.csdn.net/LYJwonderful/article/details/80662039

2.对拍

C++
#include<bits/stdc++.h>
using namespace std;

int main()
{
	double start = (double)clock() / CLOCKS_PER_SEC;
	freopen("", "", stdin);
	//your solution, but put your ans in an array.
	fclose(stdin);
	double end = (double)clock() / CLOCKS_PER_SEC;
	freopen("", "", stdin);
	freopen("res.txt", "w", stdout);
	/*write your code to adjust the test cases*/
	bool WRONG_ANSWER = false;
	if(/*.ans*/ != /*.out*/)
	{
		printf("WA on test %d\n", ...);
		printf("read: %lld; expected %lld.\n", /*.out*/, /*.ans*/);
		WRONG_ANSWER = true;
	}
	if(!WRONG_ANSWER)
	{
		if(end - start > /*time limit of the problem*/)
			puts("TLE."), puts("The answer is correct.");
		else puts("AC.");
	}
	printf("You used: %.6f s\n", end - start);
	return 0;
}

(可将 printf 等输出内容换成 cerr,其他有关内容需要自己替换)

来源:原创