Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <list>
- #define not_yet_set -1;
- using namespace std;
- typedef long int lint;
- typedef unsigned long long int ullint;
- class target {
- public:
- lint x, y;
- };
- // overloading this operator will help us on list sorting.
- bool operator<(target a, target b)
- {
- return (a.x == b.x) ? (a.x < b.x) : (a.y < b.y);
- }
- int main()
- {
- lint N, w;
- ullint M1, M2;
- ifstream fin ("sonar.in");
- ofstream fout("sonar.out");
- target point;
- list<target> targets;
- // Beginning of Input
- fin >> N >> M1 >> M2;
- for(ullint i=0; i<M1; i++)
- {
- fin >> point.x >> w; // we are given the pos in x axis.
- point.y = N - w + 1; // process the signal to get the pos in y axis.
- targets.push_back(point);
- }
- for(ullint i=0; i<M2; i++)
- {
- fin >> point.y >> w;
- point.x = N - w + 1;
- targets.push_back(point);
- }
- // End of input.
- targets.sort();
- target last;
- last.x = last.y = not_yet_set;
- list<target>::iterator it;
- for(it = targets.begin(); it != targets.end(); it++)
- {
- //since the list is sorted, same instances of a point are near.
- if(it->x == last.x && it->y == last.y)
- {
- //if we find a double appearance, we must remove
- // the other instances of that point from our list.
- it = targets.erase(it);
- it--;
- continue;
- }
- last.x = it->x;
- last.y = it->y;
- }
- //Output the final solution.
- fout << (int) targets.size() << "\n";
- for(it=targets.begin(); it != targets.end(); it++)
- fout << it->x << " " << it->y << "\n";
- //And pray for the testcases:
- // *pray* *pray*...
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement