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;}
原创粉丝点击