HDU 2418 Another Easy Problem(模拟)
来源:互联网 发布:淘宝店家一元拍 编辑:程序博客网 时间:2024/05/24 07:14
题目地址
题意:给你n个学生的编号(string),m门课的班级编号,班级容量以及上课时间,q个选课请求,问有多少个请求可以达成(两门课的时间不能重叠才能选)。选课顺序是要按照课程在input出现的顺序排序,相同课程的按请求出现的顺序排序。
思路:就直接模拟,要注意细节,我就是排序规则函数里面把id写成了sx,WA了一个小时,这种题目仔细就好了,详细看代码
#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <set>#include <stack>#include <cmath>#include <cstdio>#include <algorithm>#include <iomanip>#define N 200010#define M 400010#define LL __int64#define inf 0x3f3f3f3f#define lson l,mid,ans<<1#define rson mid+1,r,ans<<1|1#define getMid (l+r)>>1#define movel ans<<1#define mover ans<<1|1using namespace std;const LL mod = 1000000007;struct node { set<int> kc; set<int> time;}student;struct nope { int cap; set<int> time;}kc;struct nodp { string name; int id; int sx;}px[510];map<int, nope> kcj;//课程集map<string, node> xsj;//学生集map<int, int >kcx;//课程序bool cmp(nodp a, nodp b) { if (kcx[a.id] == kcx[b.id]) { return a.sx < b.sx; } return kcx[a.id] < kcx[b.id];}int main() { cin.sync_with_stdio(false); int Case = 1; int n, m, q; int a, b, c; int ans; string str; while (cin >> n >> m >> q) { kcj.clear(); xsj.clear(); kcx.clear(); student.kc.clear(); student.time.clear(); for (int i = 1; i <= n; i++) { cin >> str; xsj[str] = student; } for (int i = 1; i <= m; i++) { kc.time.clear(); cin >> a; cin >> kc.cap; cin >> b; kcx[a] = i; for (int j = 0; j < b; j++) { cin >> c; kc.time.insert(c); } kcj[a] = kc; } for (int i = 0; i < q; i++) { cin >> px[i].name >> px[i].id; px[i].sx = i; } sort(px, px + q, cmp); ans = 0; for (int i = 0; i < q; i++) { str = px[i].name; a = px[i].id; kc = kcj[a]; student = xsj[str]; if (kc.cap <= 0 || student.kc.count(a) != 0) { continue; } b = 1; for (set<int> ::iterator it = kc.time.begin(); it != kc.time.end(); it++) { if (student.time.count(*it) != 0) { b = 0; break; } } if (b == 1) { ans++; kcj[a].cap--; xsj[str].kc.insert(a); for (set<int> ::iterator it = kc.time.begin(); it != kc.time.end(); it++) { xsj[str].time.insert(*it); } } } cout << "Case " << Case++ << ": " << ans << endl; } return 0;}
阅读全文
0 0
- HDU 2418 Another Easy Problem(模拟)
- 【模拟】Another Easy Problem
- FZU_1753 Another Easy Problem
- fzu1753 Another Easy Problem
- Another Easy Problem FZU
- 【STL】 hdu2418 Another Easy Problem
- fzu 1753 Another Easy Problem
- HDU-5475 An easy problem(模拟||(倒着计算+线段树))
- FZU1753 Another Easy Problem【组合数】
- hdu 2055 An easy problem (水题)
- hdu 2055 An easy problem (水题)
- hdu 2055 An easy problem (java)
- hdu An easy problem (背包)
- HDU 2601 An easy problem (数学)
- 数学 hdu 2601 (An easy problem)
- HDU 2601 An easy problem(思维)
- HDU 2601 An easy problem (数论)
- hdu-An Easy Problem
- 函数,集合
- 三种快速排序算法以及快速排序的优化
- redis实现单点登录系统
- heap_4.c详解--------FreeRTOS内存管理
- LeetCode【2】-Add Two Numbers
- HDU 2418 Another Easy Problem(模拟)
- jquery中$(":input")和$("input")有什么区别
- 爬虫学习笔记(三)——Re正则表达式
- HashMap的工作原理
- 机器学习与线性回归
- UPCOJ 4201
- TexturePacker免费申请注册码
- 二维关联数组转字符串
- HashMap相关问题