1
I’m trying to solve the problem Wifi of OBI 2018 and I had the idea to create a code that will read and store the coordinates of the rooms and then check if it is "docking" (outside) another room. After that, the code should add 1 for each room that is not internal to another, so I will get the necessary value of wifi’s. However, every time the code is executed, it returns the total number of rooms, causing error. Below is the code:
#include <iostream>
using namespace std;
int main(){
int N, res = 0;
typedef struct{
long int x1, y1, x2, y2;
int e;
}sala;
cin >> N;
sala v[N];
for(int i=0;i<N;i++){
cin >> v[i].x1 >> v[i].y1 >> v[i].x2 >> v[i].y2;
v[i].e = 1;
}
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
if(v[i].x1 < v[j].x1 && v[i].y1 < v[j].y1 && v[i].x2 > v[j].x2 && v[i].y2 > v[j].y2){
v[i].e = 0;
break;
}
}
}
for(int i=0;i<N;i++){
res += v[i].e;
}
cout << res << endl;
return 0;
}