HDU 4022 Bombing[set]

题意: 知道了n 个基地的位置和m个炸弹的安放点,每个炸弹可以炸掉一行或一竖,炸掉的基地要从地图上去掉,对于每次操作输出该炸弹炸掉的基地个数。

分析:用set集合容器,每去掉一个基地就从集合中删掉。

#include <stdio.h>
#include <string.h>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

typedef map<int,multiset<int> >line;
map<int,multiset<int> >xx;
map<int,multiset<int> >yy;

int cal(line &x, line &y,int pos)
{
    int res = x[pos].size();
    multiset<int>::iterator it;
    for (it=x[pos].begin(); it!=x[pos].end();it++)
        y[*it].erase(pos);
    x[pos].clear();
    return res;
}

int main()
{
    int n, m;
    int c, d;
    int x, y;
    while (scanf("%d %d",&n,&m),n||m)
    {
        xx.clear();
        yy.clear();
        while (n--)
        {
            scanf("%d %d",&x,&y);
            xx[x].insert(y);
            yy[y].insert(x);
        }
        
        while (m--)
        {
            scanf("%d %d",&c, &d);
            int res;
            if (c == 0)
                 res = cal(xx,yy,d);
            else res = cal(yy,xx,d);
            printf("%d\n",res);
        }
        puts("");
    }
    return 0;
}
posted @ 2012-11-05 21:33  'wind  阅读(166)  评论(0编辑  收藏  举报