zoukankan      html  css  js  c++  java
  • CF刷题-Codeforces Round #481-G. Petya's Exams

    题目链接:https://codeforces.com/contest/978/problem/G

    题目大意:n天m门考试,每门考试给定三个条件,分别为:1、可以开始复习的日期。2、考试日期。3、必须要复习的时间。根据以上条件,给出每天的安排,每天可以做三件事:1、考试。2、复习。3、休息

    题解:先假设每天都在休息,然后依次填东西,策略是最先考试的最先复习

    AC代码:

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<map>
    #include<iostream>
    #include<vector>
    #include<string>
    #include<cmath>
    #include<set>
    
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    const int N = 100+5;
    struct exam{
        int b;
        int s;
        int d;
        int c;
    }e[N];
    bool cmp(exam& a,exam& b){
        return a.d < b.d;
    }
    int ans[N];
    int main(void){
        int n,m;
        memset(ans,0,sizeof(ans));
        scanf("%d%d",&n,&m);
        for(int i = 1;i <= m;i++){
            scanf("%d%d%d",&e[i].s,&e[i].d,&e[i].c);
            e[i].b = i;
        }
        sort(e+1,e+m+1,cmp);
        int ok = 1;
        for(int i = 1;i<=m;i++){
            if(ok){
                for(int j=e[i].s;;j++){
                    if(j == e[i].d && e[i].c != 0){
                        ok = 0;
                        printf("-1");
                        break;
                    }
                    if(e[i].c == 0){
                        ans[e[i].d] = m+1;
                        break;
                    }
                    if(ans[j] == 0){
                        ans[j] = e[i].b;
                        e[i].c--;
                    }
                }
            }
        }
        if(ok){
            for(int i = 1;i<=n;i++){
                printf("%d",ans[i]);
                if(i != n){
                    printf(" ");
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    scrum立会报告+燃尽图(第三周第一次)
    scrum立会报告+燃尽图(第二周第七次)
    scrum立会报告+燃尽图(第二周第六次)
    scrum立会报告+燃尽图(第二周第五次)
    scrum立会报告+燃尽图(第二周第四次)
    006_for
    005_while
    003_if_else
    002_how to use getpass
    图像旋转
  • 原文地址:https://www.cnblogs.com/doubest/p/10190863.html
Copyright © 2011-2022 走看看