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. 【转】: 探索Lua5.2内部实现:虚拟机指令(2) MOVE & LOAD

    name args desc OP_MOVE A B R(A) := R(B) OP_MOVE用来将寄存器B中的值拷贝到寄存器A中.由于Lua是register based vm,大部分的指令都是直接 ...

  2. 2018牛客多校第二场a题

    一个人可以走一步或者跳x步,但不能连着跳,问到这个区间里有几种走法 考虑两种状态  对于这一点,我可以走过来,前面是怎么样的我不用管,也可以跳过来但是,跳过来必须保证前一步是走的 dp[i][0]表示 ...

  3. isX字符串方法

    islower():返回True,如果字符串至少有一个字母,并且所有字母都是小写: 例如:>>> spam='Hello world' >>> spam.islow ...

  4. Training Models

    In this page, I am going to talk about the 'hello world' model that is linear regression and train i ...

  5. Graph Theory

    Description Little Q loves playing with different kinds of graphs very much. One day he thought abou ...

  6. 2019寒假训练营寒假作业(三) 对Sketch——CM-Sketch的理解(理论题部分)

    目录 实验题部分 基本题 1.简述sketch: 2.Count-min Sketch: 开放题部分 理论部分 1.解释为什么 sketch 可以省空间 2.用流程图描述Count-min sketc ...

  7. Mac OS安装Scrapy失败

    报错: DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be re ...

  8. 某一线互联网公司前端面试题总结css部分

    1,css3选择器 :not(selector) 选择页面内所有type!=text的类型: input:not([type=text]){ color: red; font-weight: bold ...

  9. 第三部分shell编程3(shell脚本编写1)

    做监控和备份最多 1. shell脚本是什么它是一种脚本语言,并非编程语言可以使用一些逻辑判断.循环等语法可以自定义子函数是系统命令的集合shell脚本可以实现自动化运维,大大增加我们的工作效率 第一 ...

  10. Flink的序列化与flink-hadoop-compatibility

    最近 用户提交了一个问题 说他的jar包里明明包含相关的类型 但是在提交Flink作业的时候 却报出classnotfound的错误 查看之后发现 这里是flink的一个没有说的太明白的地方 用户的代 ...