AGC027 A - Candy Distribution Again
目录
题目链接
AGC027 A - Candy Distribution Again
题解
贪心即可
代码
#include<cstdio>
#include<cstring>
#include<algorithm>
#define gc getchar()
#define pc putchar
inline int read() {
int x = 0,f = 1;
char c = gc;
while(c < '0' || c > '9') {if(c == '-')f = -1; char c = getchar();}
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar();
return x * f;
}
void print(int x) {
if(x < 0) {
pc('-');
x = -x;
}
if(x >= 10) print(x / 10);
pc(x % 10 + '0');
}
const int maxn = 100007;
int a[maxn];
int main() {
int n = read(),k = read();
for(int i = 1;i <= n;++ i) a[i] = read();
std::sort(a + 1, a + n + 1);
int ans = 0;
for(int i = 1;i <= n;++ i) {
if(i < n) { if(a[i] <= k ) k -= a[i],ans ++;}
else if(i == n && a[i] == k) ans ++;
else break;
}
print(ans);
pc('\n');
}
AGC027 A - Candy Distribution Again的更多相关文章
- HDU 5291 Candy Distribution DP 差分 前缀和优化
Candy Distribution 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5291 Description WY has n kind of ...
- HDU 5291 Candy Distribution
Candy Distribution Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- Candy Distribution
Kids like candies, so much that they start beating each other if the candies are not fairly distribu ...
- poj3372 Candy Distribution
可以证明: f(k) = k *(k - 1)/ 2 (1 ≤ k ≤ n)是n的完全剩余系当且仅当n = 2 ^ t. http://poj.org/problem?id=3372
- [AtCoder AGC27A]Candy Distribution Again
题目大意:把$x$个糖果分给$n$个人,必须分完,如果第$i$个人拿到$a_i$个糖果,就会开心,输出最多多少人开心 题解:从小到大排序,判断是否可以让他开心,注意最后判断是否要少一个人(没分完) 卡 ...
- [AGC027A]Candy Distribution Again
Description AGC027A 你有一些糖果,你要把这些糖果一个不剩分给一些熊孩子,但是这帮熊孩子只要特定数目的糖果,否则就会不开心,求最多的开心人数. Solution 如果\(\sum a ...
- 【赛事总结】◇赛时·8◇ AGC-027
[赛时·8]AGC-027 日常AGC坑……还好能涨Rating +传送门+ ◇ 简单总结 感觉像打多校赛一样,应该多关注一下排名……考试的时候为了避免影响心态,管都没有管排名,就在那里死坑B题.最后 ...
- Candy 解答
Question There are N children standing in a line. Each child is assigned a rating value. You are giv ...
- 【Atcoder】AGC027 题解
A - Candy Distribution Again 大意:有x个糖给n个小朋友,必须分完,小朋友得到糖数为一个确切值的时候小朋友会开心,求最多的开心数 题解 直接排序然后贪心分,如果分到最后一个 ...
随机推荐
- Kaggle Titanic补充篇
1.关于年龄Age 除了利用平均数来填充,还可以利用正态分布得到一些随机数来填充,首先得到已知年龄的平均数mean和方差std,然后生成[ mean-std, mean+std ]之间的随机数,然后 ...
- ThinkPHP 框架2.1,2.2和3.0版本开启lite模式导致URL命令执行漏洞
在开启了Lite模式后,在ThinkPHP/extend/Mode/Lite/Dispatcher.class.php中第73行: // 解析剩余的URL参数 $res = preg_replace( ...
- js实现页面重定向
在现行的网站应用中URL重定向的应用有很多: 404页面处理.网址改变(t.sina转到weibo.com).多个网站地址(如:http://www.google.com/ .www.g.cn )等: ...
- IntelliJ IDEA配置Tomcat 与安装Tomcat失败原因
1.jdk中jre损坏,无法提供运行环境:重新下载jre安装并配置
- python中的zip、map、reduce 、lambda函数的使用。
lambda只是一个表达式,函数体比def简单很多. lambda的主体是一个表达式,而不是一个代码块.仅仅能在lambda表达式中封装有限的逻辑进去. lambda表达式是起到一个函数速写的作用.允 ...
- Java基础96 ajax技术的使用
本文知识点(目录): 1.ajax的概念 2.使用ajax技术获取服务端的数据_实例 3.使用ajax技术检查用户名是否已存在_实例 4.使用ajax技术验证登录页面的用户名和密码_实例 ...
- lodash篇之对象深度比较_.isEqual
- Laravel Cache 的缓存文件在到期后是否会自动删除
验证缓存文件是否会自动删除的目的是,防止产生大量的缓存文件,占满磁盘.因为,我最近越来越多的使用 cache 来缓存各类 token. 使用的是 file 作为 CACHE_DRIVER CACHE_ ...
- python接口自动化测试二十九:yaml配置文件的写和读
# 先安装ruamel.yaml模块 写入配置文件: import os# 先安装ruamel.yaml模块from ruamel import yaml # 将字典写入到yamldict = { ' ...
- 多行文字溢出[...]的实现(text-overflow: ellipsis)
声明:此文章为转载(点击查看原文),如有侵权24小时内删除.联系QQ:1522025433. 对于单行文字, 很简单.(详见css3产考手册 进入) css: .oneLine { width: 20 ...