考试检查
- 针对
WA\(\longrightarrow\) 对拍!!!
例:造数据
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <iostream>
using namespace std;
int getrand()
{
return (rand() << 15) + rand();//在Windows上rand所能产生的随机数很小,需要优化
}
int main()
{
srand(time(0));
freopen("xxx.in", "w", stdout);
int n = rand() % 1000 + 1;
int m = rand() % 1000 + 1;
int up = 1000;
cout << n << ' ' << m << '\n';
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
cout << rand() % up + 1 << ' ';
}
cout << '\n';
}
return 0;
}
比较:
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
while(1)
{
system("xxx.exe");//运行造数据的文件
system("xxx1.exe");//运行要交的代码
system("xxx2.exe");//运行暴力
if (system("fc xxx1.out xxx2.out")) break;//比较两个文件的结果
}
return 0;
}
产生一个 \(1\) ~ \(x\)的随机数
rand()%x+1;
产生一个 \(l\) ~ \(r\) 的随机数
rand()%(r-l+1)+l;
产生一个 \(1\) ~ \(n\) 的随机排列
for (int i = 1; i <= n; ++i)
{
z[i] = i;
}
random_shuffle(z + 1, z + n + 1);
随机输出一棵有 \(n\) 个点的树
for (int i = 2; i <= n; ++i)
{
cout << i << ' ' << rand() % (i - 1) + 1 << '\n';
}
造一张有 \(n\) 个点 \(m\) 条边的连通图
for (int i = 2; i <= n; ++i)
{
cout << i << ' ' << rand() % (i - 1) + 1 << '\n';
}
for (int i = n; i <= m; ++i)
{
cout << rand() % n + 1 << ' ' << rand() % n + 1;
}
生成质数
法 \(1\):
n = 1;
while (!is_prime(n))
n = rand() % x + 1;
法 \(2\):
n = rand() % x + 1;
while (!is_prime(n))
++n;

浙公网安备 33010602011771号