zoukankan      html  css  js  c++  java
  • HDU 4907 Task schedule

    递推,预处理。

    首先将已经占用了的时间开一个数组标$1$,例如$x$时间被占用了,那么$g[x]=1$。

    然后从后往前进行递推,如果$g[x]=0$,那么$ans[x]=x$,否则$ans[x]=ans[x+1]$。

    每一个询问$x$,直接输出$ans[x]$即可。

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<iostream>
    using namespace std;
    typedef long long LL;
    const double pi=acos(-1.0),eps=1e-8;
    void File()
    {
        freopen("D:\in.txt","r",stdin);
        freopen("D:\out.txt","w",stdout);
    }
    
    const int maxn=100010;
    int T,n,m,t[maxn];
    int g[2*maxn],ans[2*maxn];
    
    int main()
    {
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d%d",&n,&m);
            memset(g,0,sizeof g);
            for(int i=1;i<=n;i++)
            {
                int x; scanf("%d",&x);
                g[x]=1;
            }
    
            for(int i=200001;i>=1;i--)
            {
                if(g[i]==0) ans[i]=i;
                else ans[i]=ans[i+1];
            }
    
            for(int i=1;i<=m;i++)
            {
                int x; scanf("%d",&x);
                printf("%d
    ",ans[x]);
            }
        }
        return 0;
    }
  • 相关阅读:
    Alpha 冲刺 (7/10)
    Alpha 冲刺 (6/10)
    Alpha 冲刺 (5/10)
    Alpha 冲刺 (4/10)
    福大软工 · BETA 版冲刺前准备(团队)
    福大软工 · 第十一次作业
    Alpha 冲刺 (10/10)
    Alpha 冲刺 (9/10)
    Alpha 冲刺 (8/10)
    Alpha 冲刺 (7/10)
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5807545.html
Copyright © 2011-2022 走看看