Advertisement
Guest User

BRUT EVAL

a guest
Dec 8th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <random>
  4. #include <time.h>
  5.  
  6. using namespace std;
  7.  
  8. ifstream fin("input"); ofstream fout("output");
  9.  
  10. int n = 100, c = 100;
  11. int B[1100][1100];
  12. int A[1100][1100];
  13. int ans_brut[50010];
  14. int ans[50010];
  15. int X1[50100];
  16. int X2[50100];
  17. int Y1[50100];
  18. int Y2[50100];
  19.  
  20. void generator() {
  21.     for (int i = 1; i <= n; i++) {
  22.         X1[i] = (rand() % (c - 1)) + 1; //nr random intre 1 si c-1
  23.         Y1[i] = (rand() % (c - 1)) + 1; //nr random intre 1 si c-1
  24.         int addx = rand() % (c - X1[i]); //nr random intre 0 si c - X1[i]
  25.         int addy = rand() % (c - Y1[i]); //nr random intre 0 si c - Y1[i]
  26.         X2[i] = X1[i] + addx;
  27.         Y2[i] = Y1[i] + addy;
  28.     }
  29. }
  30.  
  31. void golire() {
  32.     for (int i = 1; i <= c; i++) {
  33.         for (int j = 1; j <= c; j++) {
  34.             B[i][j] = 0;
  35.             A[i][j] = 0;
  36.         }
  37.     }
  38.     for (int i = 0; i <= n; i++) {
  39.         ans_brut[i] = 0;
  40.         ans[i] = 0;
  41.     }
  42. }
  43.  
  44. void brut() {
  45.     for (int t = 1; t <= n; t++) {
  46.         for (int i = X1[t]; i <= X2[t]; i++) {
  47.             for (int j = Y1[t]; j <= Y2[t]; j++) {
  48.                 B[i][j] ++;
  49.             }
  50.         }
  51.     }
  52.     for (int i = 1; i <= c; i++) {
  53.         for (int j = 1; j <= c; j++) {
  54.             ans_brut[B[i][j]] += 1;
  55.         }
  56.     }
  57. }
  58.  
  59. void solve() {
  60.     for (int i = 1; i <= n; i++) {
  61.         A[X1[i]][Y1[i]] += 1;
  62.         A[X1[i]][Y2[i] + 1] -= 1;
  63.         A[X2[i] + 1][Y1[i]] -= 1;
  64.         A[X2[i] + 1][Y2[i] + 1] += 1;
  65.     }
  66.     for (int i = 1; i <= c; i++) {
  67.         for (int j = 1; j <= c; j++) {
  68.             A[i][j] += A[i - 1][j] + A[i][j - 1] - A[i - 1][j - 1];
  69.             ans[A[i+1][j+1]] += 1;
  70.         }
  71.     }
  72. }
  73.  
  74. bool compare() {
  75.     for (int i = 1; i <= n; i++) {
  76.         if (ans[i] != ans_brut[i]) {
  77.             return false;
  78.         }
  79.     }
  80.     return true;
  81. }
  82.  
  83. int main()
  84. {
  85.     srand(time(NULL)); //mereu ai un alt seed -> in functie de timp
  86.     int t = 10000;
  87.  
  88.     while (t--) {
  89.         golire();
  90.         generator();
  91.         brut();
  92.         solve();
  93.         if (!compare()) {
  94.             fout << "WA" << '\n';
  95.             fout << c << '\n';
  96.             fout << n << '\n';
  97.             for (int i = 1; i <= n; i++) {
  98.                 fout << X1[i] << " " << Y1[i] << " " << X2[i] << " " << Y2[i] << '\n';
  99.             }
  100.             return 0;
  101.         }
  102.         cerr << t << " : " << "OK" << '\n';
  103.     }
  104.  
  105.  
  106.     return 0;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement