HDU 4022 - Bombing (multiset+离散化)

6 篇文章 0 订阅

http://acm.hdu.edu.cn/showproblem.php?pid=4022

题意:

给你n个二维坐标点。

按顺序问你m条和坐标轴平行的直线,能去掉多少点。

去掉的点不重复计算。

 

POINT:

点会重复,所以用multiset。

还是很简单的,不说了。直接看代码吧。

 

#include <set>
#include <map>
#include <vector>
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define  LL long long
const int N = 100000+22;

multiset<int>x[N],y[N];

map<int,int>X;
map<int,int>Y;
multiset<int>::iterator it;
int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m)&&(n+m)){
        int cntx=0,cnty=0;
        X.clear();Y.clear();
        for(int i=1;i<=n;i++){
            x[i].clear();y[i].clear();
        }
        for(int i=1;i<=n;i++){
            int a,b;scanf("%d%d",&a,&b);
            if(X[a]==0) X[a]=++cntx;
            if(Y[b]==0) Y[b]=++cnty;
            a=X[a];b=Y[b];
            x[a].insert(b);
            y[b].insert(a);
        }
        while(m--){
            int k,a;scanf("%d%d",&k,&a);
            if(!k){//x
                if(X[a]==0)printf("0\n");
                else{
                    a=X[a];
                    //if(a>=N) while(1);
                    printf("%ld\n",x[a].size());
                    while(x[a].size()>0){
                        it=x[a].begin();
                        y[*it].erase(a);
                        x[a].erase(*it);
                    }
                }
            }else{
                if(Y[a]==0)printf("0\n");
                else{
                    a=Y[a];
                    //if(a>=N) while(1);
                    printf("%ld\n",y[a].size());
                    while(y[a].size()>0){
                        it=y[a].begin();
                        x[*it].erase(a);
                        y[a].erase(*it);
                    }
                }
            }
        }
        printf("\n");
    }


}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值