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. Siki_Unity_2-1_API常用方法和类详细讲解(上)

    Unity 2-1 API常用方法和类详细讲解(上) 任务1&2:课程前言.学习方法 && 开发环境.查API文档 API: Application Programming I ...

  2. 深入理解java虚拟机学习笔记(一)

    第二章 Java内存区域与内存溢出异常 运行时数据区域 程序计数器(Program Counter Register) 程序计数器:当前线程所执行的字节码行号指示器.各条线程之间计数器互不影响,独立存 ...

  3. 【转】一款已上市MMO手游地图同步方案总结

    转自游戏开发主席 1. 客户端地图格子的相关知识 在2.5D的MMO游戏里,角色是通过3D的方式渲染,2D的地图是通过2D的方式显示,所以在客户端一般会有三个坐标系: a) 3D坐标系:所有需要3D渲 ...

  4. KVM嵌套虚拟化

    1. 检查环境 $ grep -E 'svm|vmx' /proc/cpuinfo ~]#  lsmod | grep kvm kvm_intel             170181  0 kvm  ...

  5. STM32F4 编程手册学习1_编程模型

    STM32F4 programming manual_1 1. 处理器模式与特权等级 处理器模式分为以下两种: 线程模式: 用来执行应用软件: 处理器从reset出来时,进入线程模式: CONTROL ...

  6. C Program基础-二维数组

    一维数组可以看作一行连续的数据,只有一个下标.C语言允许构造二维数组甚至多维数组,在实际问题中有时候常常需要用到二维数组(例如数学上的矩阵),二维数组有两个下标,以确定某个元素在数组中的位置. (一) ...

  7. protected、public、private

    一.protected成员 1. 受保护的成员的可访问性 对于一个类的protected成员,①该类的用户(如类对象)不能访问它,②该类的派生类的成员(及其友元)可以访问它. 派生类的成员及其友元不能 ...

  8. 对Android体系结构的理解--后续会补充

    1.最底层_硬件 任何Android设备最底层的硬件包括 显示屏, wifi ,存储设备 等. Android最底层的硬件会根据需要进行裁剪,选择自己需要的硬件. 2.Linux内核层 该层主要对硬件 ...

  9. LintCode-211.字符串置换

    字符串置换 给定两个字符串,请设计一个方法来判定其中一个字符串是否为另一个字符串的置换. 置换的意思是,通过改变顺序可以使得两个字符串相等. 样例 "abc" 为 "cb ...

  10. 【Redis】- 延时任务

    引言 在开发中,往往会遇到一些关于延时任务的需求.例如 生成订单30分钟未支付,则自动取消 生成订单60秒后,给用户发短信 对上述的任务,我们给一个专业的名字来形容,那就是延时任务.那么这里就会产生一 ...