Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
自己编的这题的测试数据生成代码这个代码有一点小缺陷: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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator