HDU 4022 Bombing(map+multiset)

It’s a cruel war which killed millions of people and ruined series of cities. In order to stop it, let’s bomb the opponent’s base. 
It seems not to be a hard work in circumstances of street battles, however, you’ll be encountered a much more difficult instance: recounting exploits of the military. In the bombing action, the commander will dispatch a group of bombers with weapons having the huge destructive power to destroy all the targets in a line. Thanks to the outstanding work of our spy, the positions of all opponents’ bases had been detected and marked on the map, consequently, the bombing plan will be sent to you. 
Specifically, the map is expressed as a 2D-plane with some positions of enemy’s bases marked on. The bombers are dispatched orderly and each of them will bomb a vertical or horizontal line on the map. Then your commanded wants you to report that how many bases will be destroyed by each bomber. Notice that a ruined base will not be taken into account when calculating the exploits of later bombers. 

Input

Multiple test cases and each test cases starts with two non-negative integer N (N<=100,000) and M (M<=100,000) denoting the number of target bases and the number of scheduled bombers respectively. In the following N line, there is a pair of integers x and y separated by single space indicating the coordinate of position of each opponent’s base. The following M lines describe the bombers, each of them contains two integers c and d where c is 0 or 1 and d is an integer with absolute value no more than 10 9, if c = 0, then this bomber will bomb the line x = d, otherwise y = d. The input will end when N = M = 0 and the number of test cases is no more than 50. 

Output

For each test case, output M lines, the ith line contains a single integer denoting the number of bases that were destroyed by the corresponding bomber in the input. Output a blank line after each test case.

Sample Input

3 2
1 2
1 3
2 3
0 1
1 3
0 0

Sample Output

2
1 

题目描述:给n个敌人,以及每个的坐标x,y。你有m次机会去炸每一行或者每一列,问每一次炸的个数,一个点只能被炸一次

涨见识了,STL的巧妙用法,用二维数组存坐标肯定不行(内存过大),用map存坐标

注意:每组数据完后要换行,cin会超时

#include <iostream>
#include <set>
#include <map>
#include <cstdio>

using namespace std;

typedef map<int ,multiset<int> > mp;//注意> >不要连再一起

void bomb(int k,mp &m1,mp &m2)//c++的引用
{
    printf("%d\n",m1[k].size() );
    for(multiset<int>:: iterator it=m1[k].begin() ;it!=m1[k].end();it++)
        m2[*it].erase(k);
    m1[k].clear();

}
int main()
{
    int n,m;
    mp posi1,posi2;
    while(scanf("%d%d",&n,&m)==2)
    {
        if(n==0 && m==0)break;
        int x,y;
        posi1.clear();
        posi2.clear();
        for(int i=0;i<n;i++)
        {
           scanf("%d%d",&x,&y);
            posi1[x].insert(y);
            posi2[y].insert(x);
        }
        int flag,t;
        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&flag,&t);
            if(flag)//y
                bomb(t,posi2,posi1);
            else//x
                bomb(t,posi1,posi2);
        }
        printf("\n");
    }

    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值