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;
    }
  • 相关阅读:
    ha-wordy-Write-up
    HA: Infinity Stones-Write-up
    为什么k8s引入pod概念?
    vxlan 跨网段虚拟机迁移
    交换机配置
    Git四大组件(转)
    php-fpm
    docker容器中用户自定bridge网络与默认bridge网络之间的区别
    原型链
    'style-loader', 'css-loader'使用
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5807545.html
Copyright © 2011-2022 走看看