orz kss太腻害了。

一、set和multiset基础

set和multiset会根据特定的排序准则,自动将元素进行排序。不同的是后者允许元素重复而前者不允许。

需要包含头文件:

#include <set>

set和multiset都是定义在std空间里的类模板:

二、set和multiset的功能

和所有关联式容器类似,通常使用平衡二叉树完成。事实上,set和multiset通常以红黑树实作而成。

自动排序的优点是使得搜寻元素时具有良好的性能,具有对数时间复杂度。但是造成的一个缺点就是:

不能直接改变元素值。因为这样会打乱原有的顺序。

改变元素值的方法是:先删除旧元素,再插入新元素。

存取元素只能通过迭代器,从迭代器的角度看,元素值是常数。

详见:http://blog.csdn.net/xiajun07061225/article/details/7459206

Bombing

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

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
 
Recommend
lcy
 
代码来自kss,自己的不好意思贴了
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
using namespace std;
int n,m;
map<int,multiset<int> >mp1,mp2; //mp1以x为键值,mp2以y为键值
multiset<int>::iterator it;
int main()
{
//freopen("text.txt","r",stdin);
while(~scanf("%d%d",&n,&m) && n+m){
int x,y,d;
mp1.clear(); mp2.clear();
for(int i=;i<n;i++){
scanf("%d%d",&x,&y);
mp1[x].insert(y);
mp2[y].insert(x);
}
for(int i=;i<m;i++){
int cnt=;
scanf("%d%d",&d,&x);
if(d == ){
cnt=mp1[x].size();
for(it=mp1[x].begin();it!=mp1[x].end();it++)
mp2[*it].erase(x);
mp1[x].clear();
}
else {
cnt=mp2[x].size();
for(it=mp2[x].begin();it!=mp2[x].end();it++)
mp1[*it].erase(x);
mp2[x].clear();
}
printf("%d\n",cnt);
}
printf("\n");
}
return ;
}

HDU 4022 stl multiset的更多相关文章

  1. hdu 4022 STL

    题意:给你n个敌人的坐标,再给你m个炸弹和爆炸方向,每个炸弹可以炸横排或竖排的敌人,问你每个炸弹能炸死多少个人. /* HDU 4022 G++ 1296ms */ #include<stdio ...

  2. Bombing HDU, 4022(QQ糖的消法)

    Bombing From:HDU, 4022 Submit Time Limit: 4000/2000 MS (Java/Others)      Memory Limit: 65768/65768 ...

  3. 详解C++ STL multiset 容器

    详解C++ STL multiset 容器 本篇随笔简单介绍一下\(C++STL\)中\(multiset\)容器的使用方法及常见使用技巧. multiset容器的概念和性质 \(set\)在英文中的 ...

  4. Honk's pool[STL multiset]

    目录 题目地址 题干 代码和解释 题目地址 Honk's pool(The Preliminary Contest for ICPC Asia Shenyang 2019 ) 题干 代码和解释 本题使 ...

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

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

  6. HDU 4022 Bombing (map + multiset)

    题意: 在x,y坐标范围为10 ^ -9 ~~ 10 ^ 9的坐标轴之中,有 10W个点(注意有些点可能在同一坐标上),然后有10W个询问,处理询问按照输入顺序处理,对于每个询问a,b    a == ...

  7. HDU 4022 Bombing STL 模拟题

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

  8. hdu 4022 Bombing(map,multiset)

    题意:n个基地放在2维平面,然后m个炸弹人,每个炸弹人可以炸一行或者一列,输出每个炸弹人炸掉的基地个数. 思路:用map<int,multiset<int> >对应起来一行或者 ...

  9. hdu 4398 STL

    题意描述半天描述不好,直接粘贴了 Now your team is participating a programming contest whose rules are slightly diffe ...

随机推荐

  1. SpringBoot入门,新建SpringBoot项目

    一.在Spring Initializr中创建初始化项目 https://start.spring.io/ 二.通过maven导入Idea中(解压后的项目) 解压文件 黄色的为项目需要的真正的代码 , ...

  2. 【转载】K-mer算法

    k-mer是指将reads分成包含k个碱基的字符串,一般长短为m的reads可以分成m-k+1个k-mers.举个例子吧,为了简化,有这么个reads(当然实际比这个长):AACTGACTGA.如果k ...

  3. Pomodoro APP

    2015.5.23 UITableView 的数据源刷新问题 本次发过来的版本五,实现了活动清单列表(AllEventsTableViewController).活动详情(AllEventsViewC ...

  4. 低性能3张图片轮播React组件

    import React from 'react'; import {getSwipeWay} from '../utils/swipe'; class Carousel extends React. ...

  5. c++ 输入10个数,显示它的平均分

    #include <iostream> using namespace std; void inputScores(double golfScores[], int size); void ...

  6. NOIP 2017 图书管理员

    题目描述 图书馆中每本书都有一个图书编码,可以用于快速检索图书,这个图书编码是一个 正整数. 每位借书的读者手中有一个需求码,这个需求码也是一个正整数.如果一本书的图 书编码恰好以读者的需求码结尾,那 ...

  7. a标签中javascript和void

    <body> <a href="javascript:;">点了无反应</a> <a href="javascript:void ...

  8. logging模块,程序日志模板

    6.11自我总结 1.logging模块 用于程序的运行日志 1.初级 #首先程序运行分会出现5中情况 1.logging.info('info') #程序正常运行级别为10 2.logging.de ...

  9. 【转】数据仓库ODS、DW和DM概念区分

    今天看了一些专业的解释,还是对ODS.DW和DM认识不深刻,下班后花时间分别查了查它们的概念. ODS——操作性数据 DW——数据仓库 DM——数据集市 1.数据中心整体架构   数据中心整体架构 数 ...

  10. Python的第二堂课(1)

    一.编程语言的分类 机器语言:直接使用二进制命令去编写程序. 优点:执行效率高 缺点:开发效率低 汇编语言:用英文标签代替二进制命令去编写程序 优点:开发效率高于机器语言 缺点:执行效率低于机器语言 ...