Missing a Point | PTMSSNG | CodeChef
Chef has axis-parallel rectangles in a 2D Cartesian coordinate system. These rectangles may intersect, but it is guaranteed that all their vertices are pairwise distinct.
Unfortunately, Chef lost one vertex, and up until now, none of his fixes have worked (although putting an image of a point on a milk carton might not have been the greatest idea after all…). Therefore, he gave you the task of finding it! You are given the remaining points and you should find the missing one.
Input
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains a single integer .
- Then, lines follow. Each of these lines contains two space-separated integers and denoting a vertex of some rectangle.
Output
Constraints
- the sum of over all test cases does not exceed
Subtasks
Subtask #1 (20 points):
Subtask #2 (30 points):
Subtask #3 (50 points): original constraints
The original set of points are:
Upon adding the missing point , rectangles can be formed:


Solution (C++)
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
vector<int>vec_x,vec_y;
for(int i=0; i<(4*n)-1;i++)
{
int x,y;
cin>>x>>y;
vec_x.push_back(x);
vec_y.push_back(y);
}
sort(vec_x.begin(),vec_x.end());
sort(vec_y.begin(),vec_y.end());
int ansa=0,ansb=0;
// find_it(vec_x,vec_y);
for(int i=1;i<=vec_x.size();i+=2)
{
if(vec_x[i]!=vec_x[i-1])
{
cout<<vec_x[i-1]<<" ";
break;
}
}
for(int i=1;i<=vec_y.size();i+=2)
{
if(vec_y[i]!=vec_y[i-1])
{
cout<<vec_y[i-1]<<"\n";
break;
}
}
// cout<<ansa<<" "<<ansb<<endl;
}
return 0;
}
Comments
Post a Comment