传统弱校HFUT的蒟蒻,真相只有一个

OnlineJudge测试数据生成模板

int类型数据生成一(正数最多4位):

#include <bits/stdc++.h>
using namespace std;
int main()
{
       freopen("test.in","w",stdout);//输出流都输出到 test.in
       for(int i=0;i<1e4;i++)
        cout<<rand()%10000<<endl;//随机10000个int数
       return 0;
}

int类型数据生成二(正负数最多10位):

#include<iostream>
#include<ctime>
#include<cstdlib>
#include<cstdio>
#include<fstream>
#define digit 10
using namespace std;
string LLMax="9223372036854775807";
string IntMax="2147483647";
string RandomInt()
{
    int n=rand()%digit+1;//接下来生成n位数
    string s;
    if(n==digit)//特殊处理,因为int型要在[-2^31,2^31-1]之内
    {
        s+=rand()%2+1+'0';
        for(int i=1;i<n;i++)
        {
            int temp=rand()%10;
            while(temp>IntMax[i]-'0') temp=rand()%10;
            s+=temp+'0';
        }
        return s;
    }
    if(n==1) s+=rand()%10+'0';//
    else s+=rand()%9+1+'0';//第一位为1-9之间的数
    for(int i=2;i<=n;i++) s+=rand()%10+'0';//随机产生第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=0;i<100;i++)
        cout<<RandomInt()<<endl;
    return 0;
}

 long long类型数据生成(正负数最多19位)

 

#include<iostream>
#include<ctime>
#include<cstdlib>
#include<cstdio>
#define digit 19
using namespace std;
string LLMax="9223372036854775807";
string IntMax="2147483647";
string RandomLL()
{
    int n=rand()%digit+1;//接下来生成n位数
    string s;
    if(n==digit)//特殊处理,因为int型要在[-2^63,2^63-1]之内
    {
        s+=rand()%9+1+'0';
        for(int i=1;i<n;i++)
        {
            int temp=rand()%10;
            while(temp>LLMax[i]-'0') temp=rand()%10;
            s+=temp+'0';
        }
        return s;
    }
    if(n==1) s+=rand()%10+'0';//
    else s+=rand()%9+1+'0';//第一位为1-9之间的数
    for(int i=2;i<=n;i++) s+=rand()%10+'0';//随机产生第2-n位上的数字
    if(rand()%2==1) s='-'+s;//产生负数
    return s;
}
int main()
{
    srand((unsigned)time(NULL));
    freopen("test.in","w",stdout);//输出流都输出到 test.in
    for(int i=0;i<100;i++)
        cout<<RandomLL()<<endl;
    return 0;
}

产生大整数类型(正数最多100位)

#include<iostream>
#include<ctime>
#include<cstdlib>
#include<cstdio>
#include<fstream>
#define digit 100
using namespace std;
string LLMax="9223372036854775807";
string IntMax="2147483647";
string RandomBigInteger()
{
    int n=rand()%digit+1;//接下来生成n位数
    string s;
    if(n==1) s+=rand()%10+'0';//
    else s+=rand()%9+1+'0';//第一位为1-9之间的数
    for(int i=2;i<=n;i++) s+=rand()%10+'0';//随机产生第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=0;i<100;i++)
        cout<<RandomBigInteger()<<endl;
    return 0;
}

产生字符串(最多30位)

#include<iostream>
#include<ctime>
#include<cstdlib>
#include<cstdio>
#define digit 30
using namespace std;
string LLMax="9223372036854775807";
string IntMax="2147483647";
string SmellAlphabet="abcdefghijklmnopqrstuvwxyz";
string UpperAlphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string RandomString()
{
    int n=rand()%digit+1;//接下来生成n位字符串
    string s;
    for(int i=0;i<n;i++) s+=SmellAlphabet[rand()%26];//随机产生字符串
    return s;
}
int main()
{
    freopen("test.in","w",stdout);//输出流都输出到 test.in
    srand((unsigned)time(NULL));
    for(int i=0;i<100;i++)
        cout<<RandomString()<<endl;
    return 0;
}

 

 

生成标答

#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()%50;
    cout<<n<<endl;
    while(n--)
    {
        int m=rand()%50;
        cout<<m<<endl;
        m--;
        while(m--)
        {
            cout<<rand()%20<<" ";
        }
        cout<<rand()%10<<endl;
    }
    return 0;
}
#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=0; i<n; i++)
                cin>>a[i];

            int cnt=0;
            for(i=0; i<n; i++)  //枚举所有的i,j,k
                for(j=0; j<n; j++)
                    for(k=0; k<n; k++)
                    {
                        if(a[i]+a[j]==a[k])
                            cnt++;
                    }
            cout<<cnt<<endl;
        }
    }
    
}

 

posted @ 2018-01-18 17:31  未名亚柳  阅读(457)  评论(0编辑  收藏  举报