Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

自己编的这题的测试数据生成代码

Posted by kevinliu9502 at 2014-03-22 14:46:51 on Problem 1135
这个代码有一点小缺陷:time的随机性不好,time我取的是1~n的数;在这里我有用到组合数c(n,2),因为m要小于c(n ,2),理由就不说了;可以生成1,0;包括m<n的情况,但不考虑这个情况也可以ac;
下面要输入3个数:N为测试组数,x~y为生成的范围;ac代码我就不给了!
#include<cstdio>
#include<ctime>
#include<cstring>
#include<cstdlib>
#include<iostream>
using namespace std;
const int maxn=505;
int vis[maxn][maxn];
int co[maxn][maxn];
int v[maxn];

int c(int n,int m)   //组合数;
{
    if(n<0)return 0;
    if(co[n][m])return co[n][m];
    else if(m==1||m==n-1)return co[n][m]=n;
    else if(m==0||n==m)return co[n][m]=1;
    return co[n][m]=c(n-1,m)+c(n-1,m-1);
}

int main()
{
    srand(0);
    freopen("int.txt","w",stdout);
    int N;
    cin>>N;
    int x,y;
    cin>>x>>y;
    while(N--){
        int n=rand()%(y-x)+x;
        int m=rand()%(y-x)+x;
        int t=max(n,m);
        n=min(n,m);
        m=t;
        t=n;
        memset(co,0,sizeof(co));
        //printf("fn:%d ,fm:%d\n",n,m);
        //printf("c(n,2):%d\n",c(n,2));
        if(n>1){
            while(m>c(n,2)){
                m=rand()%(y-x)+x;
            }
        }
        else m=0;
        int cas=0;
        cout<<n<<' '<<m<<endl;
        memset(vis,0,sizeof(vis));
        memset(v,0,sizeof(v));
        v[1]=1;
        int cnt=0;
        while(cas!=m){
            //printf("cnt:%d\n",cnt++);
            int a=rand()%n+x,b=rand()%n+x,c=rand()%n+x;
            if(a!=b&&!vis[a][b]&&(v[a]||v[b])){
                cout<<a<<' '<<b<<' '<<c<<endl;
                vis[b][a]=vis[a][b]=1;
                v[a]=v[b]=1;
                cas++;
            }
        }
    cout<<endl;
    }
    printf("0 0\n");
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator