HDU 4022 Bombing(stl,map,multiset,iterater遍历)

题目

参考了     1     2

#define  _CRT_SECURE_NO_WARNINGS

//用的是STL中的map 和 multiset 来做的,代码写起来比较简洁,也比较好容易理解。
//multiset可以允许重复
//multiset<int>::iterator it;  用来遍历

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

//#define IN freopen("c:\\Users\\nit\\desktop\\input.txt", "r", stdin)
//#define OUT freopen("c:\\Users\\nit\\desktop\\output.txt", "w", stdout)
//int gcd(int a,int b){return b==0?a:gcd(b,a%b);}

// 建立一个 map,从 int 到 一个 multiset 容器的映射
typedef map<int,multiset<int> > line;    // 两个>间一定要加个空格
line yy,xx;    //定义x,y坐标各自对应的map

int bomb(line &xx, line &yy, int post)
{
    multiset<int>::iterator it;
    int ans = xx[post].size();
    for(it=xx[post].begin(); it!=xx[post].end(); it++)
    {
        yy[*it].erase(post);  //multiset 去除一个元素
    }
    xx[post].clear();  //清空multiset
    return ans;
}
int main()
{
    int n,m,x,y,i;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        if(n==0&&m==0)break;
        for(i=0;i<n;i++)
        {
            scanf("%d%d",&x,&y);
            xx[x].insert(y);
            yy[y].insert(x);
        }
        for(i=0;i<m;i++)
        {
            scanf("%d%d",&x,&y);
            if(x==0)
            printf("%d\n",bomb(xx,yy,y));
            else
            printf("%d\n",bomb(yy,xx,y));
        }
        puts("");
    }
    return 0;
}

HDU 4022 Bombing(stl,map,multiset,iterater遍历)

时间: 2024-11-07 23:10:32

HDU 4022 Bombing(stl,map,multiset,iterater遍历)的相关文章

HDU 4022 Bombing STL 模拟题

手动模拟.. #include<stdio.h> #include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<queue> #include<set> #include<map> using namespace std; #define N 10100 #define inf 1000000010 map<

HDU 4022 Bombing(基本算法-水题)

Bombing Problem Description 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 encou

hdoj 4022 Bombing(map的一对多)

问题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4022 map<int,<multiset<int> >通过嵌套实现一对多 1 #include<stdio.h> 2 #include<map> 3 #include<set> 4 const int MAXN = 100010; 5 using namespace std; 6 int main(){ 7 map<int,multise

hdu 4022 Bombing (离散化)

Bombing Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 3176    Accepted Submission(s): 1195 Problem Description It’s a cruel war which killed millions of people and ruined series of cities. In

HDU 2112 HDU Today(STL MAP + Djistra)

题目链接:HDU Today 立即集训要開始,抓紧时间练练手,最短路的基础题,第一次用STL的map 题目非常水,可是错了N遍.手贱了.本题不优点理的就是把地名转化为数字 #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <map> #define N 155 #define INF 1e7 using namespace

hdu 4022 Bombing

Bombing Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 2650    Accepted Submission(s): 990 Problem Description It’s a cruel war which killed millions of people and ruined series of cities. In o

hdu 4585 Shaolin(STL map)

Problem Description Shaolin temple is very famous for its Kongfu monks.A lot of young men go to Shaolin temple every year, trying to be a monk there. The master of Shaolin evaluates a young man mainly by his talent on understanding the Buddism script

Bombing HDU - 4022

Bombing HDU - 4022 题意:给出n个目标,m个炸弹,每个炸弹可以炸一行或者一列,问每一个炸弹摧毁了多少目标. 可以用STL做,也可以二分做. 这是kuangbin的代码~ 用STL很简洁,但是慢 1 /* 2 HDU 4022 3 G++ 1296ms 4 5 6 */ 7 8 9 #include<stdio.h> 10 #include<iostream> 11 #include<set> 12 #include<map> 13 #inc

Bombing HDU, 4022(QQ糖的消法)

Bombing From:HDU, 4022 Submit Time Limit: 4000/2000 MS (Java/Others)      Memory Limit: 65768/65768 K (Java/Others) Problem Description It's a cruel war which killed millions of people and ruined series of cities. In order to stop it, let's bomb the