HDU_4022_Bombing

来源:互联网 发布:阿里巴巴软件开发 编辑:程序博客网 时间:2024/06/14 00:02

HDU_5022_Bombing
题意:在二维平面坐标上有N个基地,现在用M个新武器去炸,每次新武器可以炸一行或者一列(0, 1标明)并输出炸的基地数,已经被炸过的基地不计。
思路:用STL的map去做,分键为横坐标与与之对应所有纵坐标的映射和纵坐标与与之对应的所有横坐标的映射,即键为x对应所有y的集合和键为y对应所有x的集合,故应该用multiset。若炸弹炸的是行则输出对应纵坐标的映射并将之clear以免影响之后的计数,炸列同理。

#include <iostream>#include <cstdio>#include <map>#include <set>using namespace std;void pop(map<int, multiset<int> > &a, map<int, multiset<int> > &b, int k){    printf("%d\n", a[k].size());    for(multiset<int>::iterator i=a[k].begin(); i!=a[k].end(); i++)        b[*i].erase(k);    a[k].clear();}int main(){    int n, m, x, y;    while(true)    {        scanf("%d%d", &n, &m);        if(n==0 && m==0)return 0;        map<int, multiset<int> > a;        map<int, multiset<int> > b;        for(int i = 0; i < n; i++)        {            scanf("%d%d", &x, &y);            a[x].insert(y);            b[y].insert(x);        }        for(int j=0; j<m; j++)        {            scanf("%d%d", &x, &y);           if(x==0)                pop(a,b,y);            else                pop(b,a,y);        }        printf("\n");    }    return 0;}
0 0
原创粉丝点击