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 ...
随机推荐
- Centos7源码安装MySQL5.7
a.连接数据库报111 从一台linux远程连接另一台linux上的MySQL,出现ERROR 2003 (HY000): Can't connect to MySQL server on 'xxx. ...
- 我的VIM
我的vim 压缩包地址:https://pan.baidu.com/s/1bo1kt8j
- C# SQL帮助类
C# SQL帮助类 本人自己封装的SQLHelper类,执行sql server与Oracle数据的增删改查 vs自带的Oracle数据库引用需要安装Oracle客户端,如不想安装Oracle客户端, ...
- 使用一个数组存储一个英文句子"java is an object oriented programing language"
class fun { public static void main(String[] args) { String str="java is an object oriented pro ...
- 学习笔记 Java类的封装、继承和多态 2014.7.10
1.问题:toString()没搞懂? int a = 1; Integer aa = new Integer(a); //这是实现的过程 System.out.println("Hello ...
- C 标准库 - <math.h>
C 标准库 - <math.h> 简介 math.h 头文件定义了各种数学函数和一个宏.在这个库中所有可用的功能都带有一个 double 类型的参数,且都返回 double类型的结果. 库 ...
- UVA 12338 - Anti-Rhyme Pairs(后缀数组+RMQ)
UVA 12338 - Anti-Rhyme Pairs 题目链接 题意:给定一些字符串,每次询问求出两个字符串的最长公共前缀的长度 思路:把字符串排序,就能求出height和rank数组,然后利用R ...
- pjblog支持QQ、新浪微博一键登录
转载地址: http://www.ruisoftcn.com/blog/article.asp?id=955
- windows下taskkill命令简介
1.简介 使用该工具可以按照进程 ID (PID) 或映像名称终止任务. 2.语法 TASKKILL [/S system [/U username [/P [password]]]] ...
- git+jenkins
开发写代码的演变 一个开发单打独斗,撸代码,开发网站,自由自在 多个开发同时开发一个网站,同时改一份代码.但是同时改一个文件会导致冲突 分支结构,每天上班第一件事克隆代码,下班前最后一件事合并代码 好 ...