Bombing

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 3492    Accepted Submission(s): 1323

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 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 109, 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
 
Source
 
 
题意:输入 n,m
接着 n个点的 横纵坐标
m个询问(a,b) a为0代表 输出 横坐标为b的点的个数 并删除扫描过的点
                        a为1代表 输出 纵坐标为b的点的个数  并删除 扫描过的点
解法:map标记 set离散  有重点 用multiset
        STL大法好 涨姿势
 
注意 格式 PE  GG;
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a,b;
map<int,multiset<int> >mp1;
map<int,multiset<int> >mp2;
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==0&&m==0)
break;
mp1.clear();
mp2.clear();
for(int i=1; i<=n; i++)
{
scanf("%d %d",&a,&b);
mp1[a].insert(b);
mp2[b].insert(a);
}
for(int i=1; i<=m; i++)
{
scanf("%d%d",&a,&b);
if(a==0)
{
printf("%d\n",mp1[b].size());
for(multiset<int>::iterator it=mp1[b].begin(); it!=mp1[b].end(); it++)
mp2[*it].erase(b);
mp1[b].clear();
}
else
{ printf("%d\n",mp2[b].size());
for(multiset<int>::iterator it=mp2[b].begin(); it!=mp2[b].end(); it++)
mp1[*it].erase(b);
mp2[b].clear();
}
}
printf("\n");
} return 0;
}

HDU4022 Bombing STL的更多相关文章

  1. HDU 4022 Bombing STL 模拟题

    人工模拟.. #include<stdio.h> #include<iostream> #include<algorithm> #include<vector ...

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

    题目 参考了     1     2 #define _CRT_SECURE_NO_WARNINGS //用的是STL中的map 和 multiset 来做的,代码写起来比较简洁,也比较好容易理解. ...

  3. [HDOJ4022]Bombing(离散化+stl)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4022 一个图上有n个点,之后m个操作,每次操作一行或者一列.使得这一行或者这一列的点全部消除.每次操作 ...

  4. 详细解说 STL 排序(Sort)

    0 前言: STL,为什么你必须掌握 对于程序员来说,数据结构是必修的一门课.从查找到排序,从链表到二叉树,几乎所有的算法和原理都需要理解,理解不了也要死记硬背下来.幸运的是这些理论都已经比较成熟,算 ...

  5. STL标准模板库(简介)

    标准模板库(STL,Standard Template Library)是C++标准库的重要组成部分,包含了诸多在计算机科学领域里所常见的基本数据结构和基本算法,为广大C++程序员提供了一个可扩展的应 ...

  6. STL的std::find和std::find_if

    std::find是用来查找容器元素算法,但是它只能查找容器元素为基本数据类型,如果想要查找类类型,应该使用find_if. 小例子: #include "stdafx.h" #i ...

  7. STL: unordered_map 自定义键值使用

    使用Windows下 RECT 类型做unordered_map 键值 1. Hash 函数 计算自定义类型的hash值. struct hash_RECT { size_t operator()(c ...

  8. C++ STL简述

    前言 最近要找工作,免不得要有一番笔试,今年好像突然就都流行在线笔试了,真是搞的我一塌糊涂.有的公司呢,不支持Python,Java我也不会,C有些数据结构又有些复杂,所以是时候把STL再看一遍了-不 ...

  9. codevs 1285 二叉查找树STL基本用法

    C++STL库的set就是一个二叉查找树,并且支持结构体. 在写结构体式的二叉查找树时,需要在结构体里面定义操作符 < ,因为需要比较. set经常会用到迭代器,这里说明一下迭代器:可以类似的把 ...

随机推荐

  1. jQuery的图片懒加载

    jQuery的图片懒加载 function imgLazyLoad(options) { var settings = { Id: $('img'), threshold: 100, effectsp ...

  2. 提升方法-AdaBoost

    提升方法通过改变训练样本的权重,学习多个分类器(弱分类器/基分类器)并将这些分类器进行线性组合,提高分类的性能. AdaBoost算法的特点是不改变所给的训练数据,而不断改变训练数据权值的分布,使得训 ...

  3. 算法与数据结构实验题 6.4 Summary

    ★实验任务 可怜的 Bibi 丢了好几台手机以后,看谁都像是小偷,他已经在小本本上记 下了他认为的各个地点的小偷数量. 现在我们将 Bibi 的家附近的地形抽象成一棵有根树.每个地点都是树上的 一个节 ...

  4. 内部网关协议RIP 路由选择算法(距离向量)

    RIP是一种基于距离向量的路由选择协议 RIP的距离就是指的跳数,没经过一个路由,就是一跳,RIP允许一跳路径最多经过15个路由器,所以16个的话就相当于不可以到达了 RIP协议的特点: 1:仅和相邻 ...

  5. lintcode-158-两个字符串是变位词

    158-两个字符串是变位词 写出一个函数 anagram(s, t) 判断两个字符串是否可以通过改变字母的顺序变成一样的字符串. 说明 What is Anagram? Two strings are ...

  6. iOS开发自定义试图切换

    CATransition *transition = [CATransition animation]; transition.duration = 1.0f; transition.timingFu ...

  7. Ubuntu启用root账号登录系统

    使用root账号登陆Ubuntu系统,实现起来本身没啥难度,运行passwd root即可,然后在/etc/ssh/sshd_config里面修改PermitRootLogin yes即可.不过研究的 ...

  8. 异常--try..catch

    class Program { static void Main(string[] args) { try { object obj = null; int N = (int)obj; } catch ...

  9. Go语言【第三篇】:Go变量和常量

    Go语言变量 变量来源于数学,是计算机语言中能存储计算结果或能表示值抽象概念.变量可以通过变量名访问.Go语言变量名由字母.数字.下划线组成,其中首字母不能为数字,声明变量的一般形式是使用var关键字 ...

  10. [洛谷P4430]小猴打架

    题目大意:有$n$个点,问有多少种连成生成树的方案. 题解:根据$prufer$序列可得,$n$个点的生成树有$n^{n-2}$个,每种生成树有$(n-1)!$种生成方案,所以答案是$n^{n-2}( ...