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\n",ans);
return 0;
}
Codeforces Round #303 (Div. 2) D. Queue —— 贪心的更多相关文章
- 水题 Codeforces Round #303 (Div. 2) D. Queue
题目传送门 /* 比C还水... */ #include <cstdio> #include <algorithm> #include <cstring> #inc ...
- Codeforces Round #303 (Div. 2) D. Queue 水题贪心
题目: 题意:给你n个数值,要求排列这个序列使得第k个数值的前K-1个数的和>=第k个数值的个数尽可能多: #include <iostream> #include <cstd ...
- Codeforces Round #303 (Div. 2) C. Woodcutters 贪心
C. Woodcutters Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/probl ...
- Codeforces Round #303 (Div. 2) D. Queue 傻逼题
C. Woodcutters Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/probl ...
- Codeforces Round #303 (Div. 2) C dp 贪心
C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #303 (Div. 2) B 水 贪心
B. Equidistant String time limit per test 1 second memory limit per test 256 megabytes input standar ...
- 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String
题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...
- DP Codeforces Round #303 (Div. 2) C. Woodcutters
题目传送门 /* 题意:每棵树给出坐标和高度,可以往左右倒,也可以不倒 问最多能砍到多少棵树 DP:dp[i][0/1/2] 表示到了第i棵树时,它倒左或右或不动能倒多少棵树 分情况讨论,若符合就取最 ...
- 水题 Codeforces Round #303 (Div. 2) A. Toy Cars
题目传送门 /* 题意:5种情况对应对应第i或j辆车翻了没 水题:其实就看对角线的上半边就可以了,vis判断,可惜WA了一次 3: if both cars turned over during th ...
随机推荐
- SRM1154--Topcoder初体验
SRM 711 DIV2 <br > 在frank_c1的帮助下,辣鸡Xiejiadong也开始做Topcoder辣...... <br > 这算是一次Topcoder的初体验 ...
- 第1章 CentOS安装
一.安装说明 1.1 CentOS介绍 CentOS(Community Enterprise Operating System,中文意思是:社区企业操作系统)是Linux ...
- JS没有contains方法,可以用indexof实现
我们很多时候会不自觉的在js代码里对一个字符串进行如下操作: str.contains("substr"); 但是js里面没有这个方法去判断字符串str是不是包含substr,而j ...
- Java中PO、BO、VO、DTO、POJO、DAO概念及其作用和项目实例图(转)
PO(bean.entity等命名): Persistant Object持久对象,数据库表中的记录在java对象中的显示状态 最形象的理解就是一个PO就是数据库中的一条记录. 好处是可以把一条记录作 ...
- http put/delete方式请求
HttpClient使用Delete方式提交数据 1. http请求主要有以下几种方法来对指定资源做不同操作: HTTP/1.1协议中共定义了八种方法(有时也叫“动作”)来表明Request-URI指 ...
- VS2015中跑OpenGL红宝书第八版的示例代码
OpenGL的东西快忘光了,把角落的第八版红宝书拿出来复习一下 从书中的地址下了个示例代码结果新系统(Win10+VS2015)各种跑不起来,懊恼之后在网上疯狂搜索资料终于跑起来了,记录一下 一.环境 ...
- Android---简单的动画
- 利用VideoView播放视频
package com.qianhua.ui; 002 003 import android.app.Activity; 004 import android.content.Intent; 00 ...
- servlet基础梳理(一)
将近一个月没看servlet了,再加上第一次学习也没有深入.仅仅是笼统的看了一遍,编了一点基础案例就过去了,如今再去看感觉跟没学过一样.这里再用一点时间把这些基础都梳理一下,加深印象并为以后高速复习做 ...
- vue2.0 + vux (五)api接口封装 及 首页 轮播图制作
1.安装 jquery 和 whatwg-fetch (优雅的异步请求API) npm install jquery --save npm install whatwg-fetch --save 2. ...