/ Published in: C++
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* * grading-testcase.cpp * * Created on: Jan 26, 2011 * Author: dirk */ #include <cstdlib> #include <iostream> #include <ctime> #include <random> #include <vector> #include <iterator> #include <boost/random/mersenne_twister.hpp> // for mt19937 #include <boost/random/uniform_int.hpp> #include <boost/random/variate_generator.hpp> int main(int argc, char **argv) { int n(0), m(0); if(argc < 3 || (n=std::atoi(argv[1])) <= 0 || (m=std::atoi(argv[2])) <= 0) { std::cout << "N = 0 || M = 0, leaving...\n"; return EXIT_FAILURE; } boost::mt19937 rng(std::time(0)); boost::uniform_int<> uniform_dist(1, n); boost::variate_generator<boost::mt19937&, boost::uniform_int<> > order_roller(rng, uniform_dist); std::vector<int> events(n, 0); for(int i = 0; i < n; ++i) events[i] = i+1; std::cout << n << '\n'; for(int i = 0; i <= m; ++i) { std::random_shuffle(events.begin(), events.end(), order_roller); std::copy(events.begin(), events.end(), std::ostream_iterator<int>(std::cout, " ")); std::cout << '\n'; } }