In:
#include <bits/stdc++.h>
using namespace std;
int random(int l,int r){
return (long long)rand()*rand()%(r-l+1)+l;
}
int main()
{
srand(int(time(0)));//加上这个才能真正产生随机数
for(int i = 1; i <= 10; i ++){
string fileName = "";
string c = to_string(i);
fileName += c;
fileName += ".in";
freopen(fileName.c_str(), "w", stdout);
//下面写要生成的数据
fclose(stdout);
}
return 0;
}
Out:
#include <bits/stdc++.h>
using namespace std;
void solve(){
//这里放自己程序的主函数
//自己程序的其他函数,直接写在其他地方就行了
}
int main(void)
{
for(int i = 1; i <= 10; i ++)
{
string fileName = "";
string c = to_string(i);//确定对应的标号
fileName += c;
fileName += ".in";
freopen(fileName.c_str(), "r", stdin);
string fileNameout = "";
string s = to_string(i);
fileNameout += s;
fileNameout += ".out";
freopen(fileNameout.c_str(), "w", stdout);
solve();
}
fclose(stdin);
fclose(stdout);
return 0;
}
一些不容易造的数据的生成方法
任意一个1~n的排列
用vertor存在1~n,然后随机下标(0-vector.size()),生成此数,然后删除vector里面这个数,循环操作。
数据保证图联通
先生成一颗树,再随机生成边。
生成树的方法:枚举到第
i
i
i 个点,在
(
1
,
i
−
1
)
(1,i-1)
(1,i−1) 当中随机选一个点连边。