STL(pair map set vector priority_queue) poj 3297
POJ 3297
算法竞赛初级杂烩包
题意:学生选课,没个学生只能选一门课。大写字符是课的名字,小写是人名。如果课程后面有多个相同名字算一个,如果一个人选多门课,则他选不上课,输出课和每门课选课人数
思路:
map<string,set<int> > stu:一个学生名对应他选了哪几门课
map<string,ser<int> > pro:课程名对应有几个学生选了他,set存对应的学生
vector<pair<int,string> > ans:最后结果,课程名对应所选学生人数
a[]:判断一个学生是否只选了一门课
//#pragma comment(linker, "/STACK:167772160")//手动扩栈~~~~hdu 用c++交
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <utility>
#include <algorithm>
#include <vector>
#include <map>
// #include<malloc.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define LL long long
const int inf = 0x3f3f3f3f;
const double eps = 1e-;
const double pi = acos(-);
const LL MOD = 1e9+;
// const LL p = 1e9+7;
// inline int r(){
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
// return x*f;
// }
map<string,int> stu;
map<string,set<int> > pro;
vector<pair<int,string> > ans; int a[],n,m;
string str,book;
void init(){
stu.clear();
pro.clear();
ans.clear();
clc(a,);
n=m=;
} bool cmp(const pair<int,string> &a,const pair<int,string> &b){
if(a.first==b.first) return a.second<b.second;
return a.first>b.first;
} void work(){
std::map<string,set<int> >::iterator it;
std::set<int>::iterator q;
for(it=pro.begin();it!=pro.end();it++){
int cnt=;
for(q=it->second.begin();q!=it->second.end();q++){
if(a[*q]==) cnt++;
}
ans.push_back(make_pair(cnt,it->first));
}
sort(ans.begin(),ans.end(),cmp);
std::vector<pair<int,string> >::iterator p;
for(p=ans.begin();p!=ans.end();p++){
cout<<p->second<<" "<<p->first<<endl;
}
} int main(){
// freopen("in.txt","r",stdin);
init();
while(getline(cin,str)){
if(str[]=='') break;
else if(str[]=='') {
work();
init();
continue;
}
else{
if(str[]>='A'&&str[]<='Z'){
book=str;
pro[book].insert(-);
}
else{
std::map<string,int>::iterator it = stu.find(str);
if(it==stu.end())
stu[str]=m++;
std::set<int>::iterator q=pro[book].find(stu[str]);
if(q==pro[book].end()){
a[stu[str]]++;
pro[book].insert(stu[str]);
}
}
}
}
return ;
}
STL(pair map set vector priority_queue) poj 3297的更多相关文章
- Tangled in Cables(Kruskal+map容器处理字符串)
/** 题意: 给你两个城市之间的道路(无向图),求出需要的 电缆.如果大于所提供的,就输出Not enough ... 否则输出所需要的电缆长度. 输入:N (给 ...
- 容器适配器(stack、 queue 、priority_queue)源码浅析与使用示例
一.容器适配器 stack queue priority_queue stack.queue.priority_queue 都不支持任一种迭代器,它们都是容器适配器类型,stack是用vector/d ...
- (Set, Map, Collections工具类)JAVA集合框架二
Java集合框架部分细节总结二 Set 实现类:HashSet,TreeSet HashSet 基于HashCode计算元素存放位置,当计算得出哈希码相同时,会调用equals判断是否相同,相同则拒绝 ...
- 4-Pandas数据预处理之数据转换(df.map()、df.replace())
在数据分析中,根据需求,有时候需要将一些数据进行转换,而在Pandas中,实现数据转换的常用方法有: 利用函数或是映射 可以将自己定义的或者是其他包提供的函数用在Pandas对象上实现批量修改. ap ...
- java自定义类型 作为HashMap中的Key值 (Pair<V,K>为例)
由于是自定义类型,所以HashMap中的equals()方法和hashCode()方法都需要自定义覆盖. 不然内容相同的对象对应的hashCode会不同,无法发挥算法的正常功能,覆盖equals方法, ...
- poj 3159 Candies(dijstra优化非vector写法)
题目链接:http://poj.org/problem?id=3159 题意:给n个人派糖果,给出m组数据,每组数据包含A,B,c 三个数,意思是A的糖果数比B少的个数不多于c,即B的糖果数 - A的 ...
- js五种不同的遍历 (filter, map,foreach,every, some,)
var arr=[1,2,"a",2,4,1,4,"a",5,6,7,8,"aa","bb","c" ...
- (线性dp 最大连续和)POJ 2479 Maximum sum
Maximum sum Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 44459 Accepted: 13794 Des ...
- Gunner II--hdu5233(map&vector/二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5233 题意:有n颗树,第 i 棵树的高度为 h[i],树上有鸟,现在这个人要打m次枪,每次打的高度是 ...
随机推荐
- jq获取元素到底部的距离
// var wh = $(window).height(),//是文档窗口高度 // ot = $("#icoimg").offset().top,//是标签距离顶部高度 // ...
- uva 10069
简单的dp 但是一个大数加法 套用了末位大牛的类模板 #include <cstdio> #include <cstring> #include <algorithm& ...
- HDU1565+状态压缩dp
简单的压缩状态 dp /* 状态压缩dp 同hdu2167 利用滚动数组!! */ #include<stdio.h> #include<string.h> #include& ...
- Android 二维码扫描与生成
由于源代码比较多,本文不进行讲述,请下载源码. 源码来源于网络,请点击这里下载: http://files.cnblogs.com/wuyou/Android%E4%BA%8C%E7%BB%B4%E7 ...
- jquery.dataTables插件使用例子详解
DataTables是一个jQuery的表格插件.这是一个高度灵活的工具,依据的基础逐步增强,这将增加先进的互动控制,支持任何HTML表格 效果图 代码 <!doctype html> & ...
- perl杂项
perl -pi -e 's|googleapis.com|useso.com|g' `find ./ -type f` yingc@yingc:~/gcyin/test/thirdparty/ffm ...
- MyBatis之传入参数parameterType
在MyBatis的select.insert.update.delete这些元素中都提到了parameterType这个属性.MyBatis现在可以使用的parameterType有基本数据类型和Ja ...
- QDialog之屏蔽Esc键(过滤,或者丢弃)
http://blog.csdn.net/u011012932/article/details/50357323
- 启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误的解决方法!
启动 Eclipse 弹出"Failed to load the JNI shared library jvm.dll"错误的解决方法 http://blog.csdn.net/z ...
- Consistent Hashing算法-搜索/负载均衡
在做服务器负载均衡时候可供选择的负载均衡的算法有很多,包括: 轮循算法(Round Robin).哈希算法(HASH).最少连接算法(Least Connection).响应速度算法(Respons ...