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 ...
随机推荐
- 161123、ssh scp 复制文件和文件夹
复制文件或目录命令: 复制文件: (1)将本地文件拷贝到远程 scp 文件名用户名@计算机IP或者计算机名称:远程路径 本地192.168.80.100客户端 scp /root/instal ...
- LUA之面向对象
Account = { balance=0, withdraw = function (self, v) self.balance = self.balance - v end } function ...
- android 中activity调用远程service中的方法之 aidl的使用
服务端:只有服务,没有界面 1.编写interface文件,复制到 .aidl 文件中,并去掉其中的public 等修饰符.系统会自动在gen目录下生成对应的java文件 (对应本地调用中的接口文件 ...
- 启用WCF测试客户端的相关技巧
在Visual Studio之外打开WCF测试客户端有两种方法:第一种方法是到其所在路径(Visual Studio安装路径\Common7\IDE\WcfTestClient.exe)双击打开.第二 ...
- Java常用jar包用途
Java常用jar包用途: USAGE INDEX JAR NAME USAGE 1 ASM asm-2.2.3.jar ASM字节码库 2 ASM asm-commons-2.2.3.jar ASM ...
- Hive报错之java.sql.SQLException: Field 'IS_STOREDASSUBDIRECTORIES' doesn't have a default value
在创建表的时候报出如下错误: hive> create table if not exists testfile_table( > site string, > url string ...
- html 和 html5(一)(表格 | 列表 | 提交按钮 | 单选 |复选 | 框架 | 脚本 | html字符实体 )
一.框架 使用iframe来显示目录链接页面 iframe可以显示一个目标链接的页面 目标链接的属性必须使用iframe的属性,如下实例: 实例 <iframe src="demo_i ...
- [转]在iOS项目中使用CorePlot框架
转载地址:http://blog.csdn.net/llfjfz/article/details/7849190#comments Core Plot是OS X和IOS下的一个开源图形库,它提供数据的 ...
- 关于easyui的窗口和tab页面不执行js说明
一直以来群里里面很多人反应,在用tab加载界面的时候,界面里面的js不会执行.今天GodSon在此说明一下原因. 不管是window,dailog还是tab其实质最终都是继承了panel.panel有 ...
- MultiSelectComboBox(一)
1. MultiSelectComboBox.xaml <UserControl x:Class="MultiSelectComboBox.MultiSelectComboBox&qu ...