STL--map
map--概述:
|
map c |
产生一个空的map/multimap,其中不含任何元素 |
|
map c (op) |
以op为排序准则,产生一个空的map/multimap |
|
map c1(c2) |
产生某个map/multimap的副本,所有元素均被复制 |
|
map c (beg, end) |
以区间[beg; end]内的元素产生一个map/multimap |
|
map c (beg, end, op) |
以op为排序准则,利用[beg; end]内的元素生成一个map/multimap |
|
c.~map() |
销毁所有元素,释放内存 |
#include<iostream>
#include<map>
using namespace std; int main()
{
int n, ans, a, T;
cin>>T;
while(T--)
{
ans = ;
scanf("%d", &n);
map<int,int> m;
for(int i=; i<n; i++)
{
scanf("%d",&a);
m[a]++;
if(m[a]>ans)
ans=m[a];
}
printf("%d\n", ans); }
return ;
}
3.裸裸裸裸,,,,,,,,,,切着玩吧!
http://acm.hdu.edu.cn/showproblem.php?pid=1800
#include<iostream>
#include<cstdio>
#include<map>
using namespace std; int main()
{
int n;
while(scanf("%d", &n)!=EOF)
{
int i, max =-, q;
map<int, int> M;
for(i=; i<n; i++)
{
scanf("%d", &q);
M[q]++;
if(max<M[q])
max=M[q];
}
printf("%d\n", max);
}
return ;
}
2.我就是喜欢“裸体”。 来一发!
#include <iostream>
#include <map>
#include <algorithm>
using namespace std; int main()
{
//freopen( "in.txt", "r", stdin );
//freopen( "out.txt", "w", stdout );
int n;
while (cin>>n && n)
{
map <string, int> Balloon;
string s;
for (int i=; i<n; i++)
{
cin>>s;
Balloon[s]++;
}
int iMax = ;
map <string, int>::iterator point, loc;
for (point=Balloon.begin(); point!=Balloon.end(); point++)
if (iMax<point->second)
{
iMax = point->second;
loc = point;
}
cout<<loc->first<<endl;
}
return ;
}
3.此题较难一点, 草滩小恪读懂题意都很费劲(英语渣的悲哀!哭,哭,哭,)。
#include<iostream>
#include<map>
#include<set>
using namespace std; typedef map<int, multiset<int> >line;
map<int, multiset<int> >mx;
map<int, multiset<int> >my; int bomb(line &x, line &y, int pos)
{
int ret = x[pos].size();
multiset<int>::iterator it;
for(it=x[pos].begin(); it!=x[pos].end(); it++)
y[*it].erase(pos);
x[pos].clear();
return ret;
} int main()
{
int n, m, c, d, tx, ty;
while(scanf("%d%d", &n, &m)!=EOF)
{
if(n==&&m==) break;
mx.clear();
my.clear();
for(int i=; i<n; i++)
{
scanf("%d%d", &tx, &ty);
mx[tx].insert(ty);
my[ty].insert(tx);
}
for(int i=; i<m; i++)
{
scanf("%d%d", &c, &d);
int ans;
if(c==) ans = bomb(mx, my, d);
else ans = bomb(my, mx, d);
printf("%d\n", ans);
}
printf("\n");
}
return ;
}
4.这个题不太难, 就是需要些巧妙地读入处理技巧。
http://acm.hdu.edu.cn/showproblem.php?pid=1075
#include<cstdio>
#include<iostream>
#include<string>
#include<map>
using namespace std; map<string,string>mp;
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
mp.clear();
string str1,str2;
cin>>str1;
while(cin>>str1)
{
if(str1=="END")break;
cin>>str2;
mp[str2]=str1;
}
cin>>str1;
char ch;
ch=getchar();
str1="";
while()
{
while()
{
scanf("%c",&ch);
if(!((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')))break;
str1+=ch;
}
if(str1=="END")break;
if(mp.find(str1)==mp.end())cout<<str1;
else cout<<mp[str1];
str1="";
printf("%c",ch);
}
return ;
}
但是, 如果这道题的单词数据很大, 那么上面的代码就不行啦, 虽然map是基于红黑树的, 在处理重复单词时并没体现出特别的高效。 一个很好的方法就是--字典树!
STL--map的更多相关文章
- stl::map之const函数访问
如何在const成员数中访问stl::map呢?例如如下代码: string ConfigFileManager::MapQueryItem(const string& name) const ...
- hdu4941 Magical Forest (stl map)
2014多校7最水的题 Magical Forest Magical Forest Time Limit: 24000/12000 MS (Java/Others) Memory Limit ...
- [CareerCup] 13.2 Compare Hash Table and STL Map 比较哈希表和Map
13.2 Compare and contrast a hash table and an STL map. How is a hash table implemented? If the numbe ...
- STL MAP及字典树在关键字统计中的性能分析
转载请注明出处:http://blog.csdn.net/mxway/article/details/21321541 在搜索引擎在通常会对关键字出现的次数进行统计,这篇文章分析下使用C++ STL中 ...
- POJ 3096 Surprising Strings(STL map string set vector)
题目:http://poj.org/problem?id=3096 题意:给定一个字符串S,从中找出所有有两个字符组成的子串,每当组成子串的字符之间隔着n字符时,如果没有相同的子串出现,则输出 &qu ...
- STL MAP 反序迭代
ITS_NOTICE_MAP::reverse_iterator it = noticeMap.rbegin(); for ( ; it != noticeMap.rend(); ++it ) { I ...
- 泛型Binary Search Tree实现,And和STL map比较的经营业绩
问题叙述性说明: 1.binary search tree它是一种二进制树的.对于key值.比当前节点左孩子少大于右子. 2.binary search tree不是自平衡树.所以,当插入数据不是非常 ...
- Dictionary,hashtable, stl:map有什么异同?
相同点:字典和map都是泛型,而hashtable不是泛型. 不同点:三者算法都不相同 Hashtable,看名字能想到,它是采用传统的哈希算法:探测散列算法,而字典则采用的是散列拉链算法,效率较高, ...
- STL Map和multimap 容器
STL Map和multimap 容器 map/multimap的简介 map是标准的关联式容器,一个map是一个键值对序列,即(key,value)对.它提供 基于key的快速检索能力. ...
- C++ STL map使用
Map是c++的一个标准容器,它提供了很好一对一的关系,在一些程序中建立一个map可以起到事半功倍的效果,总结了一些map基本简单实用的操作!1. map构造函数:map<string , in ...
随机推荐
- Java的多线程+Socket
客户端: package com.wulala; import java.io.FileOutputStream;import java.io.IOException;import java.io.I ...
- linux配置java环境变量(详细)【转】
转自:http://www.cnblogs.com/samcn/archive/2011/03/16/1986248.html 一. 解压安装jdk 在shell终端下进入jdk-6u14-linux ...
- flex mx组件和s组件的字体兼容性不一致
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...
- 【Pro ASP.NET MVC 3 Framework】.学习笔记.3.MVC的主要工具-单元测试
IProductRepository接口定义了一个仓库,我们通过它获得.更新Product对象.IPriceReducer接口指定了一个功能,它将要对所有的Products实施,通过一个参数,降低他们 ...
- HDU 4315:Climbing the Hill(阶梯博弈)
http://acm.hdu.edu.cn/showproblem.php?pid=4315 题意:有n个人要往坐标为0的地方移动,他们分别有一个位置a[i],其中最靠近0的第k个人是king,移动的 ...
- SQLServer学习笔记<>日期和时间数据的处理(cast转化格式、日期截取、日期的加减)和 case表达式
日期和时间数据的处理. (1)字符串日期 ‘20080301’,这一串为字符串日期,但必须保证为四位的年份,两位的月份,两位的日期.例如,查询订单表日期大于‘20080301’.可以这样写: 1 se ...
- 删除ecshop云服务及授权关于官方等信息
一.删除[云服务中心] 删除/admin/cloud.php 删除/admin/templates/menu.htm中以下代码 Ajax.call('cloud.php?is_ajax=1>ac ...
- [BIM]案例
以下是中建三局BIM小组的项目,用以参考: BIM协同设计与质量控制 现实建筑物实体都是以三维空间状态存在,若用三维设计表达更具有优势.如复杂管综设计,一般情况下,二维AutoCAD设计是在建筑.结构 ...
- CSUFT 1004 This is Halloween: Saving Money
1004: This is Halloween: Saving Money Time Limit: 1 Sec Memory Limit: 128 MB Submit: 11 So ...
- 乘号在python中的用法,用乘号将元素重复在列表中
#里面:>>> a=['*5] >>> a ['] >>> a=['0,'*5] >>> a ['0,0,0,0,0,'] #外 ...