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次枪,每次打的高度是 ...
随机推荐
- 5.2:缓存中获取单例bean
5.2 缓存中获取单例bean 介绍过FactoryBean的用法后,我们就可以了解bean加载的过程了.前面已经提到过,单例在Spring的同一个容器内只会被创建一次,后续再获取bean直接从单例 ...
- What the hell is Rotate?
- The 6th Zhejiang Provincial Collegiate Programming Contest->ProblemB:Light Bulb
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3203 题意:求影子的最长长度L; 当灯,人头和墙角成一条直线时(假设此时人 ...
- Samza在YARN上的启动过程 =》 之二 submitApplication
首先,来看怎么构造一个org.apache.hadoop.yarn.client.api.YarnClient class ClientHelper(conf: Configuration) exte ...
- 【C++基础】 各种“虚”总结(ing...)
虚基类,虚函数,虚析构函数,纯虚函数,虚函数表(待补充) 一.虚基类——在继承方式(public / private)之前加 virtual class B1: virtual public B0{} ...
- Win32 DLL和MFC DLL 中封装对话框
现在最常看见的关于DLL的问题就是如何在DLL中使用对话框,这是一个很普遍的关于如何在DLL中使用资源的问题.这里我们从Win32 DLL和MFC DLL两个方面来分析并解决这个问题. ...
- CodeForce 339:A+B+C
A题:水题.. #include<stdio.h> #include<string.h> ; char s[ maxn ]; int main(){ //freopen(&qu ...
- 【转】linux下cvs配置
1. 验证是否已安装CVS #rpm -q cvs 如果能显示出类似这样的版本信息,证明已安装CVS: #cvs-1.11.19 若没有安装信息,则需要从htttp://www.cvshome.or ...
- QDialog之屏蔽Esc键(过滤,或者丢弃)
http://blog.csdn.net/u011012932/article/details/50357323
- Java API ——String类
1.String类概述 · 字符串是由多个字符组成的一串数据(字符序列),也可以看成是一个字符数组. · 字符串字符值“abc”也可以看成是一个字符串对象. · 字符串是常量,一旦被赋值,就不能被改变 ...