您的位置:首页 > 产品设计 > UI/UE

CodeForces 545D Queue (排序模拟)

2015-09-17 08:23 232 查看
【题目链接】:click here~~

【题目大意】:

有n个人,每个人都有一个等待时间,如果对于当前的人来说总等待时间超过自己的等待时间,那么这个人就会失望,问换一下顺序,使失望的人最少,问最多有多少个人不失望。

【思路】:排一下序然后加然后与当前的比较。如此。。

代码:

/*  
* Problem: CodeForces 545D
* Running time: 46MS  
* Complier: G++  
* Author: herongwei 
* Create Time:   8:20 2015/9/17 星期四
*/  
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>

using namespace std;
const int N=1e5+10;
int arr
;
int main()
{
    int t;scanf("%d",&t);
    for(int i=1; i<=t; ++i)
    {
        scanf("%d",&arr[i]);
    }
    sort(arr+1,arr+1+t);
    int ans=1;
    int temp=arr[1];
    for(int i=2; i<=t; ++i)
    {
        if(arr[i]>=temp)
        {
            ans++;
            temp+=arr[i];
        }
    }
    printf("%d\n",ans);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: