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 ...
随机推荐
- 【Pro ASP.NET MVC 3 Framework】.学习笔记.5.SportsStore一个真实的程序
我们要建造的程序不是一个浅显的例子.我们要创建一个坚固的,现实的程序,坚持使它成为最佳实践.与Web Form中拖控件不同.一开始投入MVC程序付出利息,它给我们可维护的,可扩展的,有单元测试卓越支持 ...
- 【Pro ASP.NET MVC 3 Framework】.学习笔记.3.MVC的主要工具-单元测试
IProductRepository接口定义了一个仓库,我们通过它获得.更新Product对象.IPriceReducer接口指定了一个功能,它将要对所有的Products实施,通过一个参数,降低他们 ...
- sqlite3内存不断增加的原因
数据库是这样设计的:用内存保存数据,以提高增删查改的速度,同时把数据写入磁盘,让数据落地. 如果不删除数据库里的数据,随着数据不断地添加到数据库,数据库越来越大,RES内存也越来越大. 见测试代码a. ...
- codeigniter db操作方法
链接数据库 ——- $this->load->database();//手动连接数据库 //连接多数据库 $DB1 = $this->load->database(‘group ...
- Android处理图片OOM的若干方法小结 (推荐)
众所周知,每个Android应用程序在运行时都有一定的内存限制,限制大小一般为16MB或24MB(视平台而定).因此在开发应用时需要特别关注自身的内存使用量,而一般最耗内存量的资源,一般是图片.音频文 ...
- http://www.bejson.com/go.html?u=http://www.bejson.com/demo2.html
json 解析工具http://www.bejson.com/go.html?u=http://www.bejson.com/demo2.html
- java静态块
一般情况下,如果有些代码必须在项目启动的时候就执行的时候,需要使用静态代码块,这种代码是主动执行的 静态代码块的初始化顺序 class Parent{ static String name = &q ...
- easyui tab 关闭
<div id="mm" class="easyui-menu" style="width:150px;"> &l ...
- python中字符串\r的奇怪问题
示例: 我这里有一字符串: u'北京市工商行政管理局大兴分局\r <a onclick="showJDS(\'fa641bb3be5b44a1b618433833982fee\',\' ...
- google prettify 代码高亮显示
引入js和css文件 下载地址 http://files.cnblogs.com/jaday/prettify.zip js文件代码 !function(){var q=null;window.PR_ ...