http://www.usaco.org/index.php?page=viewproblem2&cpid=759
Can someone explain how to solve this problem. I’m stuck on this problem in the guide. Here’s my code:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
freopen("billboard.in", "r", stdin);
freopen("billboard.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
int one[1000][1000];
//int two[1000][1000];
int count = 0;
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
int xx1, yy1, xx2, yy2;
cin >> xx1 >> yy1 >> xx2 >> yy2;
int xxx1, yyy1, xxx2, yyy2;
cin >> xxx1 >> yyy1 >> xxx2 >> yyy2;
// int sumx = max(x1, x2) - min(x1, x2) + 1;
// int sumy = max(y1, y2) - min(y1, y2) + 1;
for (int i = min(x1, x2); i < max(x1, x2)+1; i++) {
for (int j = min(y1, y2); j < max(y1, y2)+1; j++) {
one[i][j] = 1;
}
}
for (int i = min(xx1, xx2); i < max(xx1, xx2)+1; i++) {
for (int j = min(yy1, yy2); j < max(yy1, yy2)+1; j++) {
one[i][j] = 1;
}
}
for (int i = min(xxx1, xxx2); i < max(xxx1, xxx2)+1; i++) {
for (int j = min(yyy1, yyy2); j < max(yyy1, yyy2)+1; j++) {
one[i][j] = 0;
}
}
for (int i = 0; i <= 1000; i++) {
for (int j = 0; j <= 1000; j++) {
if (one[i][j] == 1) {
count++;
}
}
}
for (int i = 0; i >= -1000; i--) {
for (int j = 0; j >= -1000; j--) {
if (one[i][j] == 1) {
count++;
}
}
}
cout << count << '\n';
}
I’m trying to use a multidimensional array to mark points that are part of billboards. This approach is probably wrong, but will it work? Right now, its throwing a Command exited with non-zero status 139 but I can’t seem to find the fix.