• 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;
    }
  • 相关阅读:
    SQL 查询优化
    win10鼠标右键菜单在左边,怎么改回右边
    Ansible 命令
    CSV模块
    Python 常用模块
    Ansible 常用模块
    Ansible 动态配置文件
    Cluster Health
    Elasticsearch Python API
    grok常用表达式
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5807545.html
Copyright © 2020-2023  润新知