Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <random>
- #include <time.h>
- using namespace std;
- ifstream fin("input"); ofstream fout("output");
- int n = 100, c = 100;
- int B[1100][1100];
- int A[1100][1100];
- int ans_brut[50010];
- int ans[50010];
- int X1[50100];
- int X2[50100];
- int Y1[50100];
- int Y2[50100];
- void generator() {
- for (int i = 1; i <= n; i++) {
- X1[i] = (rand() % (c - 1)) + 1; //nr random intre 1 si c-1
- Y1[i] = (rand() % (c - 1)) + 1; //nr random intre 1 si c-1
- int addx = rand() % (c - X1[i]); //nr random intre 0 si c - X1[i]
- int addy = rand() % (c - Y1[i]); //nr random intre 0 si c - Y1[i]
- X2[i] = X1[i] + addx;
- Y2[i] = Y1[i] + addy;
- }
- }
- void golire() {
- for (int i = 1; i <= c; i++) {
- for (int j = 1; j <= c; j++) {
- B[i][j] = 0;
- A[i][j] = 0;
- }
- }
- for (int i = 0; i <= n; i++) {
- ans_brut[i] = 0;
- ans[i] = 0;
- }
- }
- void brut() {
- for (int t = 1; t <= n; t++) {
- for (int i = X1[t]; i <= X2[t]; i++) {
- for (int j = Y1[t]; j <= Y2[t]; j++) {
- B[i][j] ++;
- }
- }
- }
- for (int i = 1; i <= c; i++) {
- for (int j = 1; j <= c; j++) {
- ans_brut[B[i][j]] += 1;
- }
- }
- }
- void solve() {
- for (int i = 1; i <= n; i++) {
- A[X1[i]][Y1[i]] += 1;
- A[X1[i]][Y2[i] + 1] -= 1;
- A[X2[i] + 1][Y1[i]] -= 1;
- A[X2[i] + 1][Y2[i] + 1] += 1;
- }
- for (int i = 1; i <= c; i++) {
- for (int j = 1; j <= c; j++) {
- A[i][j] += A[i - 1][j] + A[i][j - 1] - A[i - 1][j - 1];
- ans[A[i+1][j+1]] += 1;
- }
- }
- }
- bool compare() {
- for (int i = 1; i <= n; i++) {
- if (ans[i] != ans_brut[i]) {
- return false;
- }
- }
- return true;
- }
- int main()
- {
- srand(time(NULL)); //mereu ai un alt seed -> in functie de timp
- int t = 10000;
- while (t--) {
- golire();
- generator();
- brut();
- solve();
- if (!compare()) {
- fout << "WA" << '\n';
- fout << c << '\n';
- fout << n << '\n';
- for (int i = 1; i <= n; i++) {
- fout << X1[i] << " " << Y1[i] << " " << X2[i] << " " << Y2[i] << '\n';
- }
- return 0;
- }
- cerr << t << " : " << "OK" << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement