【STL】 hdu2418 Another Easy Problem
来源:互联网 发布:计算机的网络功能dns 编辑:程序博客网 时间:2024/06/17 01:51
Another Easy Problem
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2418
题意:这个是选课问题,这个课程有一个选课容量和上课的时间点,题目给出课程和学生信息,再给出一些选课请求。如遇到以下情况就拒绝这些请求:1:接受这个请求会导致学生课表中出现冲突。2:课程没有剩余的容量了。3:学生已经选修个该课程。问最后一共能接受多少个请求。
题解:这个大致算个模拟题,只要细心就能AC的,特别要注意题目很隐晦的说明请求要按请求中的课程出现的顺序,课程出现的顺序相同按请求出现的顺序排序。
来源:http://blog.csdn.net/ACM_Ted
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2418
题意:这个是选课问题,这个课程有一个选课容量和上课的时间点,题目给出课程和学生信息,再给出一些选课请求。如遇到以下情况就拒绝这些请求:1:接受这个请求会导致学生课表中出现冲突。2:课程没有剩余的容量了。3:学生已经选修个该课程。问最后一共能接受多少个请求。
题解:这个大致算个模拟题,只要细心就能AC的,特别要注意题目很隐晦的说明请求要按请求中的课程出现的顺序,课程出现的顺序相同按请求出现的顺序排序。
代码:
#include<cstdio>#include<cstring>#include<string>#include<set>#include<map>using namespace std;struct course{ int cap;//容量 set<int> times;//时间点}tempc;struct student{ set<string> cou;//已选课程 set<int> times;//已选时间点}temps;map<string,student> maps;map<string,course> mapc;map<string,int> ct;struct request{ string s,c; int idx;}re[500];bool check(int x){ map<string,student>::iterator its=maps.find(re[x].s);//查找学生信息 map<string,course>::iterator itc=mapc.find(re[x].c);//查找课程信息 if(itc->second.cap<=0) return false;//课程到达容量上限 if(its->second.cou.count(re[x].c)!=0) return false;//该学生已选此课程 for(set<int>::iterator it=itc->second.times.begin();it!=itc->second.times.end();++it) { if(its->second.times.count(*it)!=0) return false;//时间点有冲突 } for(set<int>::iterator it=itc->second.times.begin();it!=itc->second.times.end();++it) { its->second.times.insert(*it); } (its->second.cou.insert(re[x].c));//课程加入学生已选课程 (itc->second.cap)--;//课程容量减一 return true;}bool cmp(const request &a,const request &b)//按课程的出现次序,出现次序相同按请求的次序排序{ if(ct[a.c]<ct[b.c]) return true; else if(ct[a.c]>ct[b.c]) return false; else return a.idx<b.idx;}int main(){ int n,m,r,t,x; char s[150],c[150]; for(int cas=1;~scanf("%d%d%d",&n,&m,&r);++cas) { mapc.clear(); maps.clear(); ct.clear(); temps.cou.clear(); temps.times.clear(); for(int i=0;i<n;++i) { scanf("%s",s); maps.insert(make_pair(string(s),temps)); } for(int i=0;i<m;++i) { tempc.times.clear(); scanf("%s",s); scanf("%d",&tempc.cap); scanf("%d",&t); for(;t--;) { scanf("%d",&x); tempc.times.insert(x); } mapc.insert(make_pair(string(s),tempc)); ct.insert(make_pair(string(s),i)); } for(int i=0;i<r;++i) { scanf("%s%s",s,c); re[i].s=string(s); re[i].c=string(c); re[i].idx=i; } sort(re,re+r,cmp); int ans=0; for(int i=0;i<r;++i) if(check(i)) ans++; printf("Case %d: %d\n",cas,ans); } return 0;}
来源:http://blog.csdn.net/ACM_Ted
- 【STL】 hdu2418 Another Easy Problem
- 【模拟】Another Easy Problem
- FZU_1753 Another Easy Problem
- fzu1753 Another Easy Problem
- Another Easy Problem FZU
- fzu 1753 Another Easy Problem
- FZU1753 Another Easy Problem【组合数】
- HDU 2418 Another Easy Problem(模拟)
- FZU 1753:Another Easy Problem _素因子分解
- FZU 1753-Another Easy Problem(求多个组合数的最大公约数)
- UVa 11991 Easy Problem from Rujia Liu? / STL-MAP
- UVA 11991 Easy Problem from Rujia Liu?(STL应用)
- uva 11991 - Easy Problem from Rujia Liu?(STL)
- UVA - 11991 - Easy Problem from Rujia Liu? (STL)
- UVA 11991Easy Problem from Rujia Liu?【STL】
- UVA 11991 - Easy Problem from Rujia Liu?【stl】
- UVA - 11991 Easy Problem from Rujia Liu?【STL】
- uva11991 Easy Problem from Rujia Liu?(STL)
- android源码随笔——消息循环机制
- B*树索引结构和内部管理
- 我的vim配置
- android 如何防止代码被反编译
- Java的反射技术
- 【STL】 hdu2418 Another Easy Problem
- 语义搜索及框计算:从百度查生僻字谈起
- oracle数据库分配用户权限
- VC调试--一位老师的回帖
- javascript 内存泄露工具使用
- linux操作系统编程——消息队列实现类似QQ功能
- NYOJ 110 剑客决斗(DP)
- IOS上OGLES 的shader文件无法打包问题
- Linux内核开发之阻塞非阻塞IO----轮询操作