• 2020牛客暑期多校训练营G9


    A

    惊叹于dalao们的智慧。

    看到数据量的时候就想到了用python,但是途中有点写不下去了,偷偷看了下别人的代码,发现这题竟然可以一行代码解决?!python果然还是强大啊……

    F

    在同一天的衣服里面,我们只能选一件,所以首先我们可以枚举权值最小的衣服是哪一件,然后我们只需找出m件衣服中权值最大的那件衣服来算出答案,如何确定呢?

    我们对所有衣服排个序,假如当前权值最小的衣服是第 i 件,那么我们就需要在所选天数衣服==m的前提下找到的第一件权值最大的衣服来算出答案即可。

    #include <bits/stdc++.h>
    #define debug freopen("r.txt","r",stdin)
    #define mp make_pair
    #define ri register int
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    const int maxn = 1e6+10;
    const int INF = 0x3f3f3f3f; 
    const int mod = 1e9+7;
    inline ll read(){ll s=0,w=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;}
    ll qpow(ll p,ll q){return (q&1?p:1)*(q?qpow(p*p%mod,q/2):1)%mod;}
    int n,m,i,p,j,x,ans,l,r,now,cnt[maxn];
    vector <pii> G;
    int main()
    {
        n=read(),m=read();
        for (i=1;i<=n;i++)
        {
            p=read();
            for (j=1;j<=p;j++) 
            {
                x=read();
                G.push_back({x,i});
            }
        }
        sort(G.begin(),G.end());
        ans=INF;r=0;
        for (l=0;l<G.size();l++)
        {
            while (now<m && r<G.size())
            {
                if (cnt[G[r].second]==0) now++;
                cnt[G[r].second]++;
                r++;
            }
            if (now==m) ans=min(ans,G[r-1].first-G[l].first);
            cnt[G[l].second]--;
            if (cnt[G[l].second]==0) now--;
        }
        cout<<ans<<endl;
        return 0; 
     } 
    View Code

    I

    贪心,找到两个最小的非0的数,较小的直接作为组成的第一个数,而所有剩下的数组成第二个数,第二个数的第一位即为两个最小的非0的数中较大的那位。

    t= int(input())
    for i in range(t):
        n=int(input())
        a=input().split()
        a.sort()
        pos=0
        while a[pos]=='0':
            pos=pos+1
        x=a[pos]
        y = a[pos + 1] + '0' * pos + ''.join(a[pos + 2:])
        print(int(x) * int(y))
    View Code

    K

    第一次dfs找出t秒后土拔鼠的位置,第二次dfs算出土拨鼠到达每个点的时间,第三次dfs算出orange到达每个点的时间,最后每个点算一遍得出答案。

    #include<iostream>
    #include<algorithm>
    #include<cstring>
    #include<vector>
    using namespace std;
    const int mm=1e5+50;
    int fo[mm],fg[mm],f[mm];
    int tt,n,t;
    vector <int> G[mm];
    void dfs1(int x,int k)
    {
        f[x]=k;
        if (k==t) tt=x;
        if (f[n]!=0) return;
        for (int i=0;i<G[x].size();i++)
            if (f[G[x][i]]==0)
                dfs1(G[x][i],k+1);
        if (f[n]==0) f[x]=0;
    }
     
    void dfs2(int x,int k)
    {
        fg[x]=k*2;
        for (int i=0;i<G[x].size();i++)
            if (fg[G[x][i]]==0)
                dfs2(G[x][i],k+1);
    }
    void dfs3(int x,int k)
    {
        fo[x]=k;
        for (int i=0;i<G[x].size();i++)
        if (fo[G[x][i]]==0)
            dfs3(G[x][i],k+1);
    }
     
    int main()
    {
        int i,j,x,y;
        scanf("%d%d",&n,&t);
        for (i=1;i<=n-1;i++)
        {
            scanf("%d%d",&x,&y);
            G[x].push_back(y);
            G[y].push_back(x);
        }
        dfs1(1,0);
        if (t>=f[n]) tt=n;
        dfs2(tt,0);
        dfs3(n,0);
        int ans=0;
        for (i=1;i<=n;i++) 
            if (fo[i]>=fg[i]) ans=max(ans,(fo[i]+1)/2);
        printf("%d
    ",ans);
        return 0;
    }
    View Code
  • 相关阅读:
    C语言——enum
    C语言——杂实例
    pc上用C语言模拟51多任务的案例程序
    C语言结构体实例-创建兔子
    C语句模拟多任务实例
    求解1^2+2^2+3^2+4^2+...+n^2的方法(求解1平方加2平方加3平方...加n平方的和)
    啊啊啊哦哦
    2013多校联合3 G The Unsolvable Problem(hdu 4627)
    c#操作excel方式三:使用Microsoft.Office.Interop.Excel.dll读取Excel文件
    揭开Socket编程的面纱
  • 原文地址:https://www.cnblogs.com/Y-Knightqin/p/13618610.html
Copyright © 2020-2023  润新知