10587 - Mayor's posters
Posted: Sun Dec 21, 2003 5:57 pm
How to solve it ? I always got TLE.
Could anybody give me some hints?
Thanks very much!
Could anybody give me some hints?
Thanks very much!
What y ?Larry wrote:Sort the intervals by x, then y, and scan.
I don't know your meaning.Larry wrote:Sort the intervals by x, then y, and scan.
Oh, I still cannot understand your meaning.Larry wrote:There is probably be a slicker way to do it, but basically, I place a y for each poster (distinct), so I'll know what's "on top", sort as follows, and then keep an array of what's "in", and a variable for being on top, and whenever that changes, I increment..
I'll try to explain.Tomson wrote:Oh, I still cannot understand your meaning.Larry wrote:There is probably be a slicker way to do it, but basically, I place a y for each poster (distinct), so I'll know what's "on top", sort as follows, and then keep an array of what's "in", and a variable for being on top, and whenever that changes, I increment..
Could you give me some more explanation?
Thanks,!!!
Try this one:miko'mized wrote:I'm still getting WA, i solved that problem using a heap and i'm sure it works. Do you have any "tricky" input sample to test my program ?
Try this one:miko'mized wrote:I'm still getting WA, i solved that problem using a heap and i'm sure it works. Do you have any "tricky" input sample to test my program ?
Yeah, I'm sorry... wrote:Obviously, this input/output pair is wrong........
Please delete/correct it
It confuses me for few days until I read the problem for many many times and make sure I understand the problem correctly........
Code: Select all
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>
#include <cassert>
#include <list>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <string>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
struct lrn {int lr,n;};
struct comp_lrn
{
bool operator () (lrn a, lrn b) const
{
return a.lr<b.lr;
}
};
set<lrn,comp_lrn> wall;
set<int> difs;
int main ()
{
set<lrn,comp_lrn>::iterator it, itend;
set<int>::iterator itd;
lrn g;
int casos, N, l, r, i;
cin >> casos;
while (casos--)
{
cin >> N;
wall.clear();
for (i=0; i<N; i++)
{
cin >> l >> r;
/* I hide the limits of other possible coincident posters */
g.lr=l, wall.erase(g);
g.lr=r, wall.erase(g);
/* I insert this new poster */
g.lr=l, g.n=i, wall.insert(g);
g.lr=r, g.n=i, wall.insert(g);
/* If l==r all the possible limits poster that must be deleted was already deleted */
if (l==r) continue;
/* I find the limits of the new poster in the data structure */
g.lr=l, it=wall.find(g);
g.lr=r, itend=wall.find(g);
difs.clear();
for (++it; it!=itend; ++it)
{
/* I store the limits of some posters hidden by the new poster */
difs.insert((*it).lr);
}
/* I erase all the poster limits hidden by the new poster */
for (itd=difs.begin(); itd!=difs.end(); ++itd)
{
g.lr=*itd;
wall.erase(g);
}
}
/* Finally, I make a set of all the different posters */
difs.clear();
for (it=wall.begin(); it!=wall.end(); ++it) difs.insert((*it).n);
cout << difs.size() << "\n";
}
return 0;
}