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次枪,每次打的高度是 ...
随机推荐
- ByteBuffer的allocate和allocateDirect区别
ByteBuffer的allocate和allocateDirect区别 在Java中当我们要对数据进行更底层的操作时,通常是操作数据的字节(byte)形式,这时常常会用到ByteBuffer这样一个 ...
- HDFS入门详解
一. 前提和设计目标 1. 硬件错误是常态,因此需要冗余,这是深入到HDFS骨头里面去了 HDFS可能由成百上千的服务器所构成,每个服务器上存储着文件系统的部分数据.我们面对的现实是构成系统的组件数目 ...
- @Entity设置OneToMany
Hibernate设置bean映射数据库的方式有配置模式与注解模式,下面通过注解模式配置OneToMany @Entity @Table(name="csdnbbs_sys_catalog& ...
- ExtJS4.2学习(13)基于表格的扩展插件---rowEditing
鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-24/182.html --------------- ...
- CQRS学习——最小单元的Cqrs(CommandEvent)[其一]
[说明:博主采用边写边思考的方式完成这一系列的博客,所以代码以附件为准,文中代码仅为了说明.] 结构 在学习和实现CQRS的过程中,首要参考的项目是这个[http://www.cnblogs.com/ ...
- HDU4539+状态压缩DP
/* 题意:n行m列的矩阵,1表示可以放东西,0表示不可以.曼哈顿距离为2的两个位置最多只能有一个位置放东西. 问最多放多少个东西. */ #include<stdio.h> #inclu ...
- Android:ScaleType设置图片
设置例子:ImageViewId.setScaleType(ScaleType.CENTER); ScaleType:设置图片显示方式 效果预览:
- 107. Binary Tree Level Order Traversal II
题目: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from ...
- DataTable ,XML和JSON相互转化
网上搜集的,保留下来了,有需要的拿去!private string DataTable2Xml(DataTable dt) { StringBuilder xmlBuilder = new Strin ...
- allegro飞线隐藏
这些都是最基本的操作,你说的应该是飞线的显示和隐藏,命令在display下面,display>show rats>net(component/all) display>blank r ...