【模拟】Another Easy Problem

Another Easy Problem

http://acm.hdu.edu.cn/showproblem.php?pid=2418



Problem Description
Nowadays, many universities no longer force students to follow a fixed curriculum; instead they allow students to choose the courses on an individual basis. However, new programs need to be written to satisfy such needs. Your job is to write such a program.
In our system, the following objects exist: Time Period, Course and Student. The relationships between the three objects are as follows:
A course has a capacity, and is associated with multiple time periods; a student can register for multiple courses in the system (resulting in a possibly conflicting schedule).
To resolve possible conflicts with the schedules as well as to ensure that the number of students registered for each course does not exceed its capacity, the system will use the logic described below to determine the result: 
Process courses, in the order they appear in the input.
For each course: Check each student's request in the order it is received, and reject the request if a) accepting the request will result in a conflict in the student's schedule, or b) if no more students could be accepted by this class, or c) the student has already enrolled in this class; otherwise, the request is accepted.

Can you solve this easy problem?
 

Input
There are multiple test cases in the input file. 
Each test case starts with three integers, N, M and R (1 <= N <= 20, 1 <= M <= 20, 0 <= R <= N * M), the number of students, the number of courses, and the number of requests, respectively.
Each of the following N lines contains one string, the ID of the student. The ID will contain no characters other than '0'...'9' The next part of each test case consists of M lines, each of which contains three integers, I, C, T, (C <= 100, T <= 30), the ID of the course, the capacity, and the number of time periods used by the course respectively; T more integers follows, representing the unique identifiers of the time periods. The description for the requests comes next, each line in the format of [Student ID](Space character)[Course ID], in the order as the requests are received. It is guaranteed that the requests are always valid, i.e., both the student ID and the course ID could be found in the description given above.
Two consecutive test cases are separated by a blank line. Input ends with End-of-File.
 

Output
For each test case, print the total number of requests accepted by the system, in the format as indicated in the sample output. 
 

Sample Input
  
2 2 4 0 1 101 1 2 3 4 102 2 1 5 0 101 1 102 1 101 0 102 1 1 0 4 5 1 1 5
 

Sample Output
  
Case 1: 3 Case 2: 0
 

Source


这题我提交了不下30多次。T-T

首先,这题从技术上来讲没有多大难度,坑就坑在英文题目的理解和题目里的陷阱吧。

题意上就是请求要按照课程在input出现的顺序排序,相同课程的按请求出现的顺序排序。

在不断的WA中,我发现了以下几个可能遇到的陷阱

1:课程可能不占用时间。  比如:课程号 111  时间无。

2:课程的时间会重复出现,比如:课程号 111   时间为 1 2 2 3 4 5.....。


#include<iostream>
#include<cstdio>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
struct ct//课程
{
    int cap;//课容量
    set<int> cor;//课时间
} temp;
struct st//学生
{
    set<int> chosed;//已选课程
    set<int> timex;//已占时间
} temt;
struct rt//请求
{
    string a;//学生号
    int b;//课程号
    int ct;//请求次序
} re[515];
map<int,struct ct> course;//课程查找
map<string,struct st> stud;//学生查找
map<int,int> flag;//课程次序
bool cmp(const struct rt &a,const struct rt &b)
{
    if(flag[a.b]<flag[b.b])  return true;
    else if(flag[a.b]==flag[b.b])
    {
        return a.ct<b.ct;
    }
    else return false;
}
int main()
{
    int n,m,r,cnt,t,a,cas=0,cname;
    string sname;
    for(cnt=0; cin>>n>>m>>r; cnt=0)
    {
        course.clear();
        stud.clear();
        flag.clear();
        temt.chosed.clear();
        temt.timex.clear();
        for(int i=0; i<n; ++i)
        {
            cin>>sname;
            stud.insert(make_pair(sname,temt));
        }
        for (int i=0; i<m; ++i)
        {
            temp.cor.clear();
            cin>>cname>>temp.cap>>t;
            flag.insert(make_pair(cname,i));
            for(int j=0; j<t; ++j)
            {
                cin>>a;
                temp.cor.insert(a);
            }
            course[cname]=temp;
        }
        map<int,struct ct>::iterator itc;
        map<string,struct st>::iterator its;
        for(int i=0; i<r; ++i)
        {
            cin>>re[i].a>>re[i].b;
            re[i].ct=i;
        }
        sort(re,re+r,cmp);//排序
        for(int i=0;i<r;++i)
        {
        sname=re[i].a;//请求的学生号
        cname=re[i].b;//请求的课程号
        bool flag=true;
        itc=course.find(cname);
        its=stud.find(sname);
        if(itc->second.cap<=0)  continue;//课程容量等于0,不接受请求
        if((its->second.chosed.count(cname))!=0) continue;//该学生已选该课程,不接受请求
        int len=itc->second.cor.size();
        for(set<int>::iterator jt=itc->second.cor.begin();jt!=itc->second.cor.end();++jt)//查看是否有时间冲突
        {
        if((its->second.timex.count(*jt))!=0)
        {
        flag=false;
        break;
        }
        }
        if(flag)//可以接受改请求
        {
        cnt++;
        (itc->second.cap)--;//该课程容量减少
        its->second.chosed.insert(cname);
        for(set<int>::iterator jt=itc->second.cor.begin();jt!=itc->second.cor.end();++jt)
        its->second.timex.insert(*jt);
        }
        }
        printf("Case %d: %d\n",++cas,cnt);
    }
    return 0;
}


内容概要:该PPT详细介绍了企业架构设计的方法论,涵盖业务架构、数据架构、应用架构和技术架构四大核心模块。首先分析了企业架构现状,包括业务、数据、应用和技术四大架构的内容和关系,明确了企业架构设计的重要性。接着,阐述了新版企业架构总体框架(CSG-EAF 2.0)的形成过程,强调其融合了传统架构设计(TOGAF)和领域驱动设计(DDD)的优势,以适应数字化转型需求。业务架构部分通过梳理企业级和专业级价值流,细化业务能力、流程和对象,确保业务战略的有效落地。数据架构部分则遵循五大原则,确保数据的准确、一致和高效使用。应用架构方面,提出了分层解耦和服务化的设计原则,以提高灵活性和响应速度。最后,技术架构部分围绕技术框架、组件、平台和部署节点进行了详细设计,确保技术架构的稳定性和扩展性。 适合人群:适用于具有一定企业架构设计经验的IT架构师、项目经理和业务分析师,特别是那些希望深入了解如何将企业架构设计与数字化转型相结合的专业人士。 使用场景及目标:①帮助企业和组织梳理业务流程,优化业务能力,实现战略目标;②指导数据管理和应用开发,确保数据的一致性和应用的高效性;③为技术选型和系统部署提供科学依据,确保技术架构的稳定性和扩展性。 阅读建议:此资源内容详尽,涵盖企业架构设计的各个方面。建议读者在学习过程中,结合实际案例进行理解和实践,重点关注各架构模块之间的关联和协同,以便更好地应用于实际工作中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值