Codeforces Round #481 (Div. 3) G. Petya's Exams (贪心,模拟)

  • 题意:你有\(n\)天的时间,这段时间中你有\(m\)长考试,\(s\)表示宣布考试的日期,\(d\)表示考试的时间,\(c\)表示需要准备时间,如果你不能准备好所有考试,输出\(-1\),否则输出你每天都在干什么,如果这一天你有考试,输出\(m+1\),如果你要准备第\(i\)场考试,输出\(i\),否则休息,输出\(0\).

  • 题解:数据范围小,直接模拟,但我们需要先贪心,即每次都要先准备最早的考试,然后直接写两个\(for\)循环就行了.

  • 代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <map>
    #include <set>
    #include <unordered_set>
    #include <unordered_map>
    #define ll long long
    #define fi first
    #define se second
    #define pb push_back
    #define me memset
    const int N = 1e6 + 10;
    const int mod = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    using namespace std;
    typedef pair<int,int> PII;
    typedef pair<long,long> PLL;
     
    int n,m;
    struct S{
        int s,d,c;
    }p[N];
    int ans[N];
    int main() {
        ios::sync_with_stdio(false);cin.tie(0);
        cin>>n>>m;
         for(int i=1;i<=m;++i){
             cin>>p[i].s>>p[i].d>>p[i].c;
         }
     
         for(int i=1;i<=n;++i){
             int cnt=-1;
             int mi=n+1;
             for(int j=1;j<=m;++j){
                 if(p[j].d==i) ans[i]=m+1;
                 if(p[j].s<=i && p[j].d>i && p[j].c>0 && (p[j].d<mi)){
                     mi=p[j].d;
                     cnt=j;
                 }
             }
             if(ans[i]==0 && cnt!=-1) ans[i]=cnt,p[cnt].c--;
         }
         for(int i=1;i<=m;++i){
             if(p[i].c>0){
                 puts("-1");
                 return 0;
             }
         }
         for(int i=1;i<=n;++i){
             printf("%d ",ans[i]);
         }
     
        return 0;
    }
    

猜你喜欢

转载自www.cnblogs.com/lr599909928/p/12934746.html