CodeForces 1000A Codehorses T-shirts(STL map、思维)

https://codeforces.com/problemset/problem/1000/A

题意:

有n个人,给出每个人的衣服的尺码,现在,将这n件衣服的尺码换成另外的n种尺码,如果有尺码一样的衣服,则不需要换,问,最少需要更换几件衣服。

思路:

map记录一下每种尺码的衣服出现的次数,然后对新尺码进行一一比对,如果新尺码的数量大于原有的,则说明要更换数量为二者差值的衣服。

代码: 

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <iostream>
 4 #include <string>
 5 #include <math.h>
 6 #include <algorithm>
 7 #include <vector>
 8 #include <stack>
 9 #include <queue>
10 #include <set>
11 #include <map>
12 #include <math.h>
13 const int INF=0x3f3f3f3f;
14 typedef long long LL;
15 const int mod=1e9+7;
16 const int maxn=1e5+10;
17 using namespace std;
18
19 int main()
20 {
21     int n;
22     cin>>n;
23     map<string,int> mp1,mp2;
24     map<string,int>::iterator it;
25     string str;
26     int num=0;
27     for(int i=1;i<=n;i++)
28     {
29         cin>>str;
30         mp1[str]++;
31     }
32     for(int i=1;i<=n;i++)
33     {
34         cin>>str;
35         mp2[str]++;
36     }
37     for(it=mp2.begin();it!=mp2.end();it++)
38     {
39         if(it->second>mp1[it->first])
40             num+=it->second-mp1[it->first];
41     }
42     printf("%d\n",num);
43     return 0;
44 }

原文地址:https://www.cnblogs.com/jiamian/p/11620288.html

时间: 2024-10-15 11:10:00

CodeForces 1000A Codehorses T-shirts(STL map、思维)的相关文章

CodeForces 1292A NEKO&#39;s Maze Game(思维)

1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <string> 5 #include <math.h> 6 #include <algorithm> 7 #include <vector> 8 #include <stack> 9 #include <queue> 10 #include <

stl::map之const函数访问

如何在const成员数中访问stl::map呢?例如如下代码: string ConfigFileManager::MapQueryItem(const string& name) const { if (_map_name_value.find(name) != _map_name_value.end()) { return _map_name_value[name]; } return ""; } 上面的代码会报错:error C2678: 二进制“[”: 没有找到接受“c

hdu 4941 Magical Forest(STL map &amp; 结构体运用)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 220    Accepted Submission(s): 105 Problem Description There is a forest c

(转载)STL map与Boost unordered_map的比较

原链接:传送门 今天看到 boost::unordered_map,它与 stl::map的区别就是,stl::map是按照operator<比较判断元素是否相同,以及比较元素的大小,然后选择合适的位置插入到树中.所以,如果对map进行遍历(中序遍历)的话,输出的结果是有序的.顺序就是按照operator< 定义的大小排序.而boost::unordered_map是计算元素的Hash值,根据Hash值判断元素是否相同.所以,对unordered_map进行遍历,结果是无序的. 用法的区别就是

ZOJ1109_Language of FatMouse(STL/map)

解题报告 题意: 略. 思路: map应用. #include <algorithm> #include <iostream> #include <cstring> #include <cmath> #include <queue> #include <vector> #include <cstdio> #include <map> using namespace std; map<string,stri

POJ训练计划3096_Surprising Strings(STL/map)

解题报告 题目传送门 题意: 给一个字符串,要求,对于这个字符串空隔为k取字符对(k=0,1,2,3,4...)要求在相同的空隔取对过程汇总,整个字符串中没有一个相同字符对如: ZGBZ: 间隔为0的字符对有: ZG.GB.BZ,三个均不相同 间隔为1的字符对有: ZG. GZ,均不相同 间隔为2的字符对有: ZZ 仅有一个,不必比较. 这种字符串定义为"surprising". 之后按照格式输出. 思路: map暴力. #include <iostream> #inclu

支持泛型AVL Tree的简单实现,并和STL map比较了插入,删除,查找的性能

1.问题描述: 1)AVL tree是一种自平衡树.它通过左右子树的高度差来控制树的平衡,当高度差是不大于1的时候,认为树是平衡的.树的平衡保证了树在极端情况下 (输入序列不够随机)的性能.很显然当左右子树高度平衡,保证了任何插入,删除,查找操作平均性能呢个,当不平衡时(有的子树很高),当 要操作的元素在这个子树时,性能会很差: 2)AVL tree 和Red black tree 都是一种平衡树,它的操作的时间复杂度是:O(lgN) ,N是树的节点的数目: 3)本文实现了AVL Tree, 并

泛型Binary Search Tree实现,And和STL map比较的经营业绩

问题叙述性说明: 1.binary search tree它是一种二进制树的.对于key值.比当前节点左孩子少大于右子. 2.binary search tree不是自平衡树.所以,当插入数据不是非常随机时候,性能会接近O(N).N是树中节点数目; 3.理想状态下.时间复杂度是O(lgN), N是树中节点的数目: 4.以下给出一个简单的实现,并比較其和STL map的性能.一样的操作,大约耗时为STL map 的2/3. 代码例如以下: #ifndef _BINARY_SEARCH_TREE_H

hdu4941 Magical Forest (stl map)

2014多校7最水的题   Magical Forest Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 253    Accepted Submission(s): 120 Problem Description There is a forest can be seen as N * M gri