Advertisement
nullzero

To Bew

Jan 9th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <cstdio>
  2. #include <set>
  3. #include <cstdlib>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. typedef pair<int,int> II;
  9. typedef set<II>::iterator iter;
  10.  
  11. int rand(int a, int b){
  12.     return rand() % (b - a + 1) + a;
  13. }
  14.  
  15. int main(){
  16.     int n = 100000, m = 10000;
  17.     set<II> used;
  18.     for(int i = 0; i < m; ++i){
  19.         while(true){
  20.             int a = rand(1, n);
  21.             int b = rand(1, n);
  22.             if(a > b) swap(a, b);
  23.             iter pos = used.lower_bound(II(a, b));
  24.             if(pos != used.end() and *pos == II(a, b)){
  25.                 // we have generated this edge!
  26.                 // try again
  27.             }else{
  28.                 printf("%d %d\n", a, b);
  29.                 used.insert(II(a, b));
  30.                 break;
  31.             }
  32.         }
  33.     }
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement