hdu 4022 Bombing(map,multiset)

题意:n个基地放在2维平面,然后m个炸弹人,每个炸弹人可以炸一行或者一列,输出每个炸弹人炸掉的基地个数。

思路:用map<int,multiset<int> >对应起来一行或者一列。(用set没过,估计数据里有多个基地位于同一个点上)

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

typedef map<int,multiset<int> > line;//两个>间一定要加个空格
map<int,multiset<int> >mx;
map<int,multiset<int> >my;

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

int main(){
    int n,m,x,y,c,d,i,ans;
    while(~scanf("%d%d",&n,&m)){
        if(n==0&&m==0)break;
        mx.clear();
        my.clear();
        for(i=0;i<n;++i){
            scanf("%d%d",&x,&y);
            mx[x].insert(y);
            my[y].insert(x);
        }
        for(i=0;i<m;++i){
            scanf("%d%d",&c,&d);
            if(c==0)ans=bomb(mx,my,d);
            else ans=bomb(my,mx,d);
            printf("%d
",ans);
        }
        printf("
");
    }
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/gongpixin/p/4751102.html