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 ...
随机推荐
- Stockbroker Grapevine(最短路)
poj——1125 Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 36112 ...
- FMDB使用Cached Statement功能
FMDB使用Cached Statement功能 在FMDB中,Cached Statement功能是一种提高SQLite数据库访问的技术.在SQLite中,所有的SQL语句都会被编译,形成预处理 ...
- vue框架及其
Vue常用UI框架 PC端: 1. ElementUI:http://element-cn.eleme.io/#/zh-CN 2. iView:https://www.iviewui.com/ 3. ...
- Ant -----ant标签和自定义任务
随便记一下 Ant的用法吧.ant ,maven, gradle ,三个打包工具到齐了,Ant 常见标签解析,ant 自定义task . <?xml version="1.0" ...
- 第四期coding_group笔记_用CRF实现分词-词性标注
一.背景知识 1.1 什么是分词? NLP的基础任务分为三个部分,词法分析.句法分析和语义分析,其中词法分析中有一种方法叫Tokenization,对汉字以字为单位进行处理叫做分词. Example ...
- android 根据图片名字获取图片id
public int getResource(String imageName){ Context ctx=getBaseContext(); int resId = getResources().g ...
- tensorflow global_variables_initializer()
老版本为 init = tf.initialize_all_variables() 新版本为 init = tf.global_variables_initializer()
- Cocos2d-x学习笔记(18)(TestCpp源代码分析-2)
本章主要讲controller.h/cpp文件的分析,该文件主要用于演示样例场景管理类TestController,用于显示全部演示样例的菜单. //controller.cpp #include & ...
- sql的一些知识_函数_汇总数据
汇总数据 avg()---------求平均数 值得注意的是:avg()只能用于一个列的平均值查询,多个列的平均值请使用多个avg() avg()忽略null值 count()-------计数(指定 ...
- 从TCP协议的原理来谈谈rst复位攻击
在谈RST攻击前,必须先了解TCP:如何通过三次握手建立TCP连接.四次握手如何把全双工的连接关闭掉.滑动窗体是怎么数据传输的.TCP的flag标志位里RST在哪些情况下出现.以下我会画一些尽量简化的 ...