zoukankan      html  css  js  c++  java
  • Codeforces Round #303 (Div. 2) D. Queue —— 贪心

    题目链接:http://codeforces.com/problemset/problem/545/D


    题解:

    问经过调整,最多能使多少个人满意。

    首先是排序,然后策略是;如果这个人对等待时间满意,则将其加入队伍中,更新当前的等候时间;如果不满意,既然等待时间最小了都不满意,那把他扔到最后,即跳过他,接着考虑下一个。


    代码如下:

    #include<cstdio>//F - F CodeForces - 545D 
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<algorithm>
    
    using namespace std;
    typedef long long ll;
    
    int a[100008];
    
    int main()
    {
        int n,ans = 1;
        ll tot;
        scanf("%d",&n);
        for(int i = 0; i<n; i++)
            scanf("%d",&a[i]);
    
        sort(a,a+n);
        tot = a[0];
        for(int i = 1; i<n; i++)
        {
            if(a[i]>=tot)//如果这样都不满意,那把他放在最后
            {
                ans++;
                tot += a[i];
            }
        }
    
        printf("%d
    ",ans);
        return 0;
    }
    


  • 相关阅读:
    Docker入门
    服务配置中心
    zuul网关
    git2
    git1
    git
    shiro授权、注解式开发
    shiro认证-SSM
    Shiro入门
    Springmvc之文件上传
  • 原文地址:https://www.cnblogs.com/DOLFAMINGO/p/7538759.html
Copyright © 2011-2022 走看看