OnlineJudge测试数据生成模板
int类型数据生成一(正数最多4位):
#include <bits/stdc++.h>
using namespace std;
int main()
{
freopen("test.in","w",stdout);//输出流都输出到 test.in
for(int i=;i<1e4;i++)
cout<<rand()%<<endl;//随机10000个int数
return ;
}
int类型数据生成二(正负数最多10位):
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<cstdio>
#include<fstream>
#define digit 10
using namespace std;
string LLMax="";
string IntMax="";
string RandomInt()
{
int n=rand()%digit+;//接下来生成n位数
string s;
if(n==digit)//特殊处理,因为int型要在[-2^31,2^31-1]之内
{
s+=rand()%++'';
for(int i=;i<n;i++)
{
int temp=rand()%;
while(temp>IntMax[i]-'') temp=rand()%;
s+=temp+'';
}
return s;
}
if(n==) s+=rand()%+'';//
else s+=rand()%++'';//第一位为1-9之间的数
for(int i=;i<=n;i++) s+=rand()%+'';//随机产生第2-n位上的数字
if(rand()%==) s='-'+s;//产生负数
return s;
}
int main()
{
freopen("test.in","w",stdout);//输出流都输出到 test.in
srand((unsigned)time(NULL));
for(int i=;i<;i++)
cout<<RandomInt()<<endl;
return ;
}
long long类型数据生成(正负数最多19位)
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<cstdio>
#define digit 19
using namespace std;
string LLMax="";
string IntMax="";
string RandomLL()
{
int n=rand()%digit+;//接下来生成n位数
string s;
if(n==digit)//特殊处理,因为int型要在[-2^63,2^63-1]之内
{
s+=rand()%++'';
for(int i=;i<n;i++)
{
int temp=rand()%;
while(temp>LLMax[i]-'') temp=rand()%;
s+=temp+'';
}
return s;
}
if(n==) s+=rand()%+'';//
else s+=rand()%++'';//第一位为1-9之间的数
for(int i=;i<=n;i++) s+=rand()%+'';//随机产生第2-n位上的数字
if(rand()%==) s='-'+s;//产生负数
return s;
}
int main()
{
srand((unsigned)time(NULL));
freopen("test.in","w",stdout);//输出流都输出到 test.in
for(int i=;i<;i++)
cout<<RandomLL()<<endl;
return ;
}
产生大整数类型(正数最多100位)
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<cstdio>
#include<fstream>
#define digit 100
using namespace std;
string LLMax="";
string IntMax="";
string RandomBigInteger()
{
int n=rand()%digit+;//接下来生成n位数
string s;
if(n==) s+=rand()%+'';//
else s+=rand()%++'';//第一位为1-9之间的数
for(int i=;i<=n;i++) s+=rand()%+'';//随机产生第2-n位上的数字
//if(rand()%2==1) s='-'+s;//产生负数
return s;
}
int main()
{
freopen("test.in","w",stdout);//输出流都输出到 test.in
srand((unsigned)time(NULL));
for(int i=;i<;i++)
cout<<RandomBigInteger()<<endl;
return ;
}
产生字符串(最多30位)
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<cstdio>
#define digit 30
using namespace std;
string LLMax="";
string IntMax="";
string SmellAlphabet="abcdefghijklmnopqrstuvwxyz";
string UpperAlphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string RandomString()
{
int n=rand()%digit+;//接下来生成n位字符串
string s;
for(int i=;i<n;i++) s+=SmellAlphabet[rand()%];//随机产生字符串
return s;
}
int main()
{
freopen("test.in","w",stdout);//输出流都输出到 test.in
srand((unsigned)time(NULL));
for(int i=;i<;i++)
cout<<RandomString()<<endl;
return ;
}
生成标答
#include <bits/stdc++.h>
using namespace std;
int main()
{
freopen("test.in","r",stdin);//cin scanf从test.in读
freopen("test.out","w",stdout);//cout printf到 test.out里面去 //+++写待测程序,即标程
}
举例:
1001: 三元组
时间限制: 1 Sec 内存限制: 128 MB
提交: 1 解决: 1
[提交][状态][讨论版][命题人:admin][Edit] [TestData]
题目描述
给你一个长度为m的数组(数组元素从0到m-1),如果数组里有a[i]+a[j]==a[k](i,j,k大于等于0并且小于m),便称之为三元组。现在给你一个数组,让你求三元组的个数。
例如m为2,里面的元素为(0,0)
那么三元组为
(a[0],a[0],a[0])
(a[0],a[0],a[1])
(a[0],a[1],a[0])
(a[0],a[1],a[1])
(a[1],a[0],a[0])
(a[1],a[0],a[1])
(a[1],a[1],a[0])
(a[1],a[1],a[1])
输出答案为8.
输入
输入正整数N,表示N例测试。接着输入N组数据,每组输入m(1<=m<=50),表示数组长度,然后输入这个数组。
输出
样例输入
2
2
0 0
5
1 1 1 2 1
样例输出
8
16
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<cstdio>
#define digit 30
using namespace std;
int main()
{
freopen("test.in","w",stdout);//输出流都输出到 test.in
int n=rand()%;
cout<<n<<endl;
while(n--)
{
int m=rand()%;
cout<<m<<endl;
m--;
while(m--)
{
cout<<rand()%<<" ";
}
cout<<rand()%<<endl;
}
return ;
}
#include <bits/stdc++.h>
using namespace std;
#define maxn 105
int a[maxn];
int main()
{
freopen("test.in","r",stdin);//cin scanf从test.in读
freopen("test.out","w",stdout);//cout printf到 test.out里面去 //+++写待测程序,即标程
int tes,n;
int i,j,k;
while(cin>>tes)
{
while(tes--)
{
cin>>n;
for(i=; i<n; i++)
cin>>a[i]; int cnt=;
for(i=; i<n; i++) //枚举所有的i,j,k
for(j=; j<n; j++)
for(k=; k<n; k++)
{
if(a[i]+a[j]==a[k])
cnt++;
}
cout<<cnt<<endl;
}
} }
OnlineJudge测试数据生成模板的更多相关文章
- [BILL WEI]stimulsoft reports DEMO自动生成模板
stimulsoft reports是一款强大的报表开发工具,能够开发各式各样的报表. 对于初学者而言,任何报表开发,刚开始都是去模仿,熟练掌握之后,自己才能独立开发,而在报表开发实际过程中, 我们所 ...
- C# T4 模板 数据库实体类生成模板(带注释,娱乐用)
说明:..,有些工具生成实体类没注释,不能和SqlServer的MS_Description属性一起使用,然后照着网上的资源,随便写了个生成模板,自娱自乐向,其实卵用都没有参考教程 1.htt ...
- springboot mail整合freemark实现动态生成模板
目标:1:springboot 整合 mail2: mail 使用freemark 实现模板动态生成(就是通过字符串生成模板,不需要在工程中写入固定模板)3: springboot 整合aop 实现日 ...
- uniapp - 更改项目生成模板、页面
每次生成项目目录都需要删除一些再添加太麻烦了,就想着能不能修改一下模板 - 当然自定义模板也能实现 好了,被我找到了. 修改以后源文件名称和格式覆盖回去即可,重新启动hbuilderx 这里可以修改e ...
- mybatis配eclise模板,mybatis快速生成模板
eclipse中mybatis得mapper文件不提示(mybatis-3-mapper.dtd,mybatis-3-config.dtd) 1.下载该文件到你的硬盘文件夹下 2.windows -- ...
- Android Studio 配置快速生成模板代码
前言 Android studio 有提供快速生成模板代码的功能,其实这个功能也可以自定义配置.此篇博客将讲解如何使用此功能 进入Settings 选择 Editor > Live Templa ...
- 【CF1443E】Long Permutation 题解(排列生成模板)
原题链接 题意简介 给定一个长度为 n 的排列 {1,2,3,...,n} .现有两种操作: 对某个区间 [l,r] 求和 将排列往后推 x 次 (按字典序) 其中 \(n,q \leq 2\time ...
- 用Case类生成模板代码
将类定义为case类会生成许多模板代码,好处在于: ①会生成一个apply方法,这样就可以不用new关键字创建新的实例. ②由于case类的构造函数参数默认是val,那么构造函数参数会自动生成访问方法 ...
- 收藏清单: python测试数据生成及代码扫描最全工具列表
Test Data manipulation 测试数据的操作和处理 faker - 生成假数据的python库 fake2db - 创建假数据库 ForgeryPy - 使用起来很简单的假数据生成库. ...
随机推荐
- python安装numpy模块
1.打开网址https://pypi.python.org/pypi/numpy,找到安装的python版本对应的numpy版本. 我的python版本是 下载的对应numpy版本是 2.将numpy ...
- python--网络通信协议
一 . osi七层协议 互联网协议按照功能不同分为osi七层或tcp/ip五层或tcp/ip四层 二 . tcp三次握手和四次挥手 我们知道网络层,可以实现两个主机之间的通信.但是这并不具体,因为,真 ...
- LeetCode(136) Single Number
题目 Given an array of integers, every element appears twice except for one. Find that single one. Not ...
- PAT Basic 1072
1072 开学寄语 下图是上海某校的新学期开学寄语:天将降大任于斯人也,必先删其微博,卸其 QQ,封其电脑,夺其手机,收其 ipad,断其 wifi,使其百无聊赖,然后,净面.理发.整衣,然后思过.读 ...
- luogu3759 [TJOI2017]不勤劳的图书管理员
分块+权值逆序对 #include <algorithm> #include <iostream> #include <cstdio> #include <c ...
- 4C. Stars
4C. Stars Time Limit: 2000ms Case Time Limit: 2000ms Memory Limit: 65536KB 64-bit integer IO forma ...
- 【JavaScript 13—应用总结】:锁屏遮罩
导读:上次说了,当弹出登录框时,由于背景色和弹出框时一样的,这样子,其实比较难聚焦到底该操作哪一块.所以,如果,有了颜色的区分,那么通过屏幕遮罩的效果,就可以将我们希望要被处理的东西突出显示.也就达到 ...
- window.location.href跳转问题
任务中遇到这样一个问题,用window.location.href跳转一到个网址,但是每次都出错,显示网址前面加上了文件所在文件夹的路径 示例如下: window.location.href=&quo ...
- (转)新ITC提交APP常见问题与解决方法(Icon Alpha,Build version,AppIcon120x120)(2014-11-17)
1)ICON无法上传,提示图片透明(有Alpha通道) 苹果现在不接受png里的Alpha了,提交的图标带有Alpha通道就提示: 简单处理:用自带的预览打开,导出时不勾选Alpha,仍保存为png格 ...
- BZOJ 3779 重组病毒 ——LCT 线段树
发现操作一很像一个LCT的access的操作. 然后答案就是路径上的虚边的数量. 然后考虑维护每一个点到根节点虚边的数量, 每次断开一条偏爱路径的时候,子树的值全部+1, 连接一条偏爱路径的时候,子树 ...