mirzayanovmr 9 years ago
parent
commit
6be6702bda

+ 2 - 1
docs/read.me

@@ -5,12 +5,13 @@ Testlib is simple library which helps you to write
     * checkers
     * validators
     * generators
+    * interactors
 for programming competitions problems.
 You can find latest release of the library on http://code.google.com/p/testlib/
 Problem development management system Polygon completely supports testlib.
 
 == How to use? ==
-Easest way is to read c++ sources in the checkers/, validators/ and generators/ folders.
+Easest way is to read c++ sources in the checkers/, validators/, generators/ and interactors/ folders.
 Also some classes and methods in testlib have documentation.
 
 Thanks for using testlib,

+ 67 - 0
generators/gen-bipartite-graph.cpp

@@ -0,0 +1,67 @@
+#include "testlib.h"
+
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include <iomanip>
+#include <string>
+#include <cstdlib>
+#include <cstdio>
+#include <cstring>
+#include <cmath>
+#include <ctime>
+#include <climits>
+#include <cassert>
+#include <vector>
+#include <queue>
+#include <stack>
+#include <deque>
+#include <set>
+#include <map>
+#include <bitset>
+#include <utility>
+#include <algorithm>
+
+#define forn(i, n) for (int i = 0; i < int(n); i++)
+
+using namespace std;
+
+int main(int argc, char* argv[])
+{
+    registerGen(argc, argv, 1);
+
+    int n = atoi(argv[1]);
+    int m = atoi(argv[2]);
+    size_t k = atoi(argv[3]);
+
+    int t = rnd.next(-2, 2);
+
+    set<pair<int,int> > edges;
+
+    while (edges.size() < k)
+    {
+        int a = rnd.wnext(n, t);
+        int b = rnd.wnext(m, t);
+        edges.insert(make_pair(a, b));
+    }
+
+    vector<pair<int,int> > e(edges.begin(), edges.end());
+    shuffle(e.begin(), e.end());
+
+    vector<int> pa(n);
+    for (int i = 0; i < n; i++)
+        pa[i] = i + 1;
+    shuffle(pa.begin(), pa.end());
+
+    vector<int> pb(m);
+    for (int i = 0; i < m; i++)
+        pb[i] = i + 1;
+    shuffle(pb.begin(), pb.end());
+
+    cout << n << " " << m << " " << e.size() << endl;
+
+    forn(i, e.size())
+        cout << pa[e[i].first] << " " << pb[e[i].second] << endl;
+
+    return 0;
+}

+ 60 - 0
generators/gen-rooted-tree-graph.cpp

@@ -0,0 +1,60 @@
+#include "testlib.h"
+
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include <iomanip>
+#include <string>
+#include <cstdlib>
+#include <cstdio>
+#include <cstring>
+#include <cmath>
+#include <ctime>
+#include <climits>
+#include <cassert>
+#include <vector>
+#include <queue>
+#include <stack>
+#include <deque>
+#include <set>
+#include <map>
+#include <bitset>
+#include <utility>
+#include <algorithm>
+
+#define forn(i, n) for (int i = 0; i < int(n); i++)
+
+using namespace std;
+
+int main(int argc, char* argv[])
+{
+    registerGen(argc, argv);
+
+    int n = atoi(argv[1]);
+    int t = atoi(argv[2]);
+
+    vector<int> p(n);
+    forn(i, n)
+        if (i > 0)
+            p[i] = rnd.wnext(i, t);
+
+    printf("%d\n", n);
+    vector<int> perm(n);
+    forn(i, n)
+        perm[i] = i;
+    shuffle(perm.begin() + 1, perm.end());
+
+    vector<int> pp(n);
+    for (int i = 1; i < n; i++)
+        pp[perm[i]] = perm[p[i]];
+
+    for (int i = 1; i < n; i++)
+    {
+        printf("%d", pp[i] + 1);
+        if (i + 1 < n)
+            printf(" ");
+    }
+    printf("\n");
+
+    return 0;
+}

+ 60 - 0
generators/gen-tree-graph.cpp

@@ -0,0 +1,60 @@
+#include "testlib.h"
+
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include <iomanip>
+#include <string>
+#include <cstdlib>
+#include <cstdio>
+#include <cstring>
+#include <cmath>
+#include <ctime>
+#include <climits>
+#include <cassert>
+#include <vector>
+#include <queue>
+#include <stack>
+#include <deque>
+#include <set>
+#include <map>
+#include <bitset>
+#include <utility>
+#include <algorithm>
+
+#define forn(i, n) for (int i = 0; i < int(n); i++)
+
+using namespace std;
+
+int main(int argc, char* argv[])
+{
+    registerGen(argc, argv, 1);
+
+    int n = atoi(argv[1]);
+    int t = atoi(argv[2]);
+
+    vector<int> p(n);
+    forn(i, n)
+        if (i > 0)
+            p[i] = rnd.wnext(i, t);
+
+    printf("%d\n", n);
+    vector<int> perm(n);
+    forn(i, n)
+        perm[i] = i;
+    shuffle(perm.begin() + 1, perm.end());
+    vector<pair<int,int> > edges;
+
+    for (int i = 1; i < n; i++)
+        if (rnd.next(2))
+            edges.push_back(make_pair(perm[i], perm[p[i]]));
+        else
+            edges.push_back(make_pair(perm[p[i]], perm[i]));
+
+    shuffle(edges.begin(), edges.end());
+
+    for (int i = 0; i + 1 < n; i++)
+        printf("%d %d\n", edges[i].first + 1, edges[i].second + 1);
+
+    return 0;
+}

+ 28 - 0
interactors/interactor-a-plus-b.cpp

@@ -0,0 +1,28 @@
+#include "testlib.h"
+#include <iostream>
+
+using namespace std;
+
+int main(int argc, char* argv[])
+{
+    setName("Interactor A+B");
+    registerInteraction(argc, argv);
+    
+    // reads number of queries from test (input) file
+    int n = inf.readInt();
+    for (int i = 0; i < n; i++)
+    {
+        // reads query from test (input) file
+        int a = inf.readInt();
+        int b = inf.readInt();
+
+        // writes query to the solution, endl makes flush
+        cout << a << " " << b << endl;
+
+        // writes output file to be verified by checker later
+        tout << ouf.readInt() << endl;
+    }
+
+    // just message
+    quitf(_ok, "%d queries processed", n);
+}

+ 3 - 2
read.me

@@ -5,13 +5,14 @@ Testlib is simple library which helps you to write
     * checkers
     * validators
     * generators
+    * interactors
 for programming competitions problems.
 You can find latest release of the library on http://code.google.com/p/testlib/
 Problem development management system Polygon completely supports testlib.
 
 == How to use? ==
-Easest way is to read c++ sources in the checkers/, validators/ and generators/ folders.
-Also classes and methods in testlib have documentation.
+Easest way is to read c++ sources in the checkers/, validators/, generators/ and interactors/ folders.
+Also some classes and methods in testlib have documentation.
 
 Thanks for using testlib,
 Mike Mirzayanov

+ 2 - 2
testlib.h

@@ -22,10 +22,10 @@
 #define _TESTLIB_H_
 
 /*
- * Copyright (c) 2005-2014
+ * Copyright (c) 2005-2015
  */
 
-#define VERSION "0.9.8-SNAPSHOT"
+#define VERSION "0.9.9"
 
 /* 
  * Mike Mirzayanov