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个小朋友,必须分完,小朋友得到糖数为一个确切值的时候小朋友会开心,求最多的开心数 题解 直接排序然后贪心分,如果分到最后一个 ...
随机推荐
- mysql基本命令[转]
1.连接Mysql 格式: mysql -h主机地址 -u用户名 -p用户密码 1.连接到本机上的MYSQL.首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u root ...
- 【Python】批量查询-提取站长之家IP批量查询的结果v1.0
0 前言 写报告的时候为了细致性,要把IP地址对应的地区给整理出来.500多条IP地址找出对应地区复制粘贴到报告里整了一个上午. 为了下次更好的完成这项重复性很高的工作,所以写了这个小的脚本. 1 使 ...
- docker在centos7系统镜像下遇到的一些问题
一.成功安装服务后发现无法启动 报错为:Failed to get D-Bus connection: Operation not permitted 系统为centos7官方版镜像,源和依赖之类的都 ...
- CAP理论介绍
经典CAP图 分布式系统的CAP理论:理论首先把分布式系统中的三个特性进行了如下归纳: ●一致性(C):在分布式系统中的所有数据备份,在同一时刻是否同样的值.(等同于所有节点访问同一份最新的数据副本) ...
- spring和hibernate集成事物管理配置方法
spring+hibernate,采用声明式事务 1.声明式事务配置 * 配置SessionFactory * 配置事务管理器 * 事务的传播特性 * 那些类那些方法使用事务 2.编写业务逻辑方法 * ...
- Oracle查询表主键、外键
项目中用到的一些Sql(oracle下的)总结: 1.查找表的所有索引(包括索引名,类型,构成列) select t.*,i.index_type from user_ind_columns t,us ...
- CSS的vertical-align
转载自https://blog.csdn.net/FE_dev/article/details/75948659 说明 vertical-align属性,是CSS属性中一个比较重要的属性,也是比较不好 ...
- webpack中的output.filename 和output.chunkFilename
filename应该比较好理解,就是对应于entry里面生成出来的文件名.比如: { entry: { "index": "pages/index.jsx" } ...
- 性能测试七:jmeter进阶之文件上传下载、定时器
一.上传下载 上传: 1,POST请求,勾选 use …for post 2,同请求一起发送文件里,填写文件名称,参数名称 3,MIME类型: application/octet-stream(非必须 ...
- appium自动化测试之元素定位
方法一 使用SDK中附带的uiautomatorviewer来定位 在SDK安装目录下的tools下有个uiautomatorviewer.bat批处理文件点击运行 运行后(注意appium desk ...