map+mulset->哈希表式 对应 集合(或者动态数组)

HDU 4022 Bombing(题目+answer)

 

一些不连续很大的数,每个数又对应着一串数字的时候,就可使用此结构

 

#include <iostream>
#include <cstdio>
#include <map>
#include <set>
using namespace std;

map<int, multiset<int> > mx;
map<int, multiset<int> > my;
int main()
{
    int n, m;
    while(scanf("%d %d", &n, &m)!=EOF && (m || n))
    {
        mx.clear();
        my.clear();
        int a, b, c, d;
        while(n--)
        {
            scanf("%d %d", &a, &b);
            mx[a].insert(b);
            my[b].insert(a);
        }
        while(m--)
        {
            scanf("%d %d", &c, &d);
            if(c)
            {
                printf("%d\n", my[d].size());
                for(multiset<int>::iterator it = my[d].begin(); it!=my[d].end(); it++)
                    mx[(*it)].erase(mx[(*it)].find(d));
            }
            else
            {
                printf("%d\n", mx[d].size());
                for(multiset<int>::iterator it = mx[d].begin(); it!=mx[d].end(); it++)
                    my[(*it)].erase(my[(*it)].find(d));
            }
        }
        printf("\n");
    }
    return 0;
}
AC Code

 

posted @ 2021-03-16 19:17  bear_xin  阅读(61)  评论(0)    收藏  举报