Anton_Lunyov

FAULT - testgen

Apr 16th, 2013
102
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<cstdio>
  2. #include<vector>
  3. #include<set>
  4. #include<map>
  5. #include<queue>
  6. #include<algorithm>
  7. #include<string>
  8. #include<utility>
  9. #include<ctime>
  10. #include<iostream>
  11. #include<cstring>
  12. #include<cassert>
  13. #include<cmath>
  14. using namespace std;
  15.  
  16. #define REP(i,a,b) for(i=a;i<b;i++)
  17. #define rep(i,n) REP(i,0,n)
  18.  
  19. #define ll long long
  20. #define RAND (rand()/(RAND_MAX+1.0))
  21.  
  22. ll nor_rand(ll a, ll b){
  23.   ll k = (b-a+1) * RAND;
  24.   return k + a;
  25. }
  26.  
  27. ll exp_rand(ll a, ll b){
  28.   ll k = exp(log(b-a+1) * RAND);
  29.   k += a;
  30.   if(k<a)k=a; if(k>b)k=b;
  31.   return k;
  32. }
  33.  
  34. ll fg_rand(ll a, ll b, int fg){
  35.   if(fg==0) return nor_rand(a,b);
  36.   if(fg==1) return exp_rand(a,b);
  37.   assert(0);
  38.   return -1;
  39. }
  40.  
  41. void gen(const char file[]){
  42.   int N, S; double P;
  43.   int i, j, k;
  44.   FILE *fp = fopen(file, "w");
  45.  
  46.   N = nor_rand(50, 200);
  47.   S = nor_rand(2*N, 1000);
  48.   P = 0.3 + RAND * 0.5;
  49.  
  50.   fprintf(fp, "%d %d\n", N, S);
  51.   rep(i,S){
  52.     vector<int> c;
  53.     rep(j,N) if(RAND < P) c.push_back(j);
  54.     random_shuffle(c.begin(), c.end());
  55.     fprintf(fp, "%d",c.size());
  56.     rep(j,c.size()) fprintf(fp, " %d",c[j]);
  57.     fprintf(fp, "\n");
  58.   }
  59.  
  60.   fclose(fp);
  61. }
  62.  
  63. int main(){
  64.   srand(time(NULL));
  65.  
  66.   int i; char file[1000];
  67.  
  68.   rep(i,40){
  69.     sprintf(file, "%d.in", i);
  70.     gen(file);
  71.   }
  72.  
  73.   rep(i,40) printf("#%d ",i); puts("");
  74.  
  75.   return 0;
  76. }
RAW Paste Data