题目大意:把$x$个糖果分给$n$个人,必须分完,如果第$i$个人拿到$a_i$个糖果,就会开心,输出最多多少人开心

题解:从小到大排序,判断是否可以让他开心,注意最后判断是否要少一个人(没分完)

卡点:

C++ Code:

#include <cstdio>
#include <algorithm>
#define maxn 111
int n, x, ans;
int a[maxn];
int main() {
scanf("%d%d", &n, &x);
for (int i = 0; i < n; i++) scanf("%d", a + i);
std::sort(a, a + n);
for (int i = 0; i < n; i++) {
if (x >= a[i]) x -= a[i], ans++;
else break;
}
if (x && ans == n) ans--;
printf("%d\n", ans);
return 0;
}

  

[AtCoder AGC27A]Candy Distribution Again的更多相关文章

  1. AGC027 A - Candy Distribution Again

    目录 题目链接 题解 代码 题目链接 AGC027 A - Candy Distribution Again 题解 贪心即可 代码 #include<cstdio> #include< ...

  2. HDU 5291 Candy Distribution DP 差分 前缀和优化

    Candy Distribution 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5291 Description WY has n kind of ...

  3. HDU 5291 Candy Distribution

    Candy Distribution Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  4. Candy Distribution

    Kids like candies, so much that they start beating each other if the candies are not fairly distribu ...

  5. AtCoder - 1999 Candy Piles

    Problem Statement There are N piles of candies on the table. The piles are numbered 1 through N. At ...

  6. AtCoder AGC002E Candy Piles (博弈论)

    神仙题..表示自己智商不够想不到... 好几次读成最后拿的赢了,导致一直没看懂题解... 题目链接: https://atcoder.jp/contests/agc002/tasks/agc002_e ...

  7. poj3372 Candy Distribution

    可以证明: f(k) = k *(k - 1)/ 2 (1 ≤ k ≤ n)是n的完全剩余系当且仅当n = 2 ^ t. http://poj.org/problem?id=3372

  8. [AGC027A]Candy Distribution Again

    Description AGC027A 你有一些糖果,你要把这些糖果一个不剩分给一些熊孩子,但是这帮熊孩子只要特定数目的糖果,否则就会不开心,求最多的开心人数. Solution 如果\(\sum a ...

  9. @atcoder - AGC002E@ Candy Piles

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定 N 堆糖果,第 i 堆包含 ai 个糖果. 现在两人进行博 ...

随机推荐

  1. jquery 操作DOM元素(1)

    .clone() 创建一个匹配的元素集合的深度拷贝. .clone([withDataAndEvents]) withDataAndEvents (默认为false) 一个Boolean 表示是否会复 ...

  2. Python线程间事件通知

    Python事件机制 事件机制:这是线程间最简单的通信机制:一个线程发送事件,其他线程等待事件事件机制使用一个内部的标志,使用set方法进行使能为True,使用clear清除为falsewait方法将 ...

  3. 线段树的应用xx中学模拟lites

    跟昨天那个自己写的,没有按照模板来的一看风格就不相类似,今天模拟赛的时候就是用的我的那个自己YY的代码,才拿了10分.个人认为关键的问题应该在于对于数据的处理太过繁琐了,所以回来之后,就拿了大佬的程序 ...

  4. Latex 使用笔记,取消目录

    不使用标准模板(如ieee或者acm的模板)的前提下: \usepackage{hyperref} \hypersetup{bookmarks={false}} 或者 \usepackage[book ...

  5. spring-传统AOP

    Spring传统AOP AOP的增强类型 AOP联盟定义了Advice(org.aopalliance.aop.Interface.Advice) 五类(目标类方法的连接点): 1.  前置通知(or ...

  6. linux文件属性更改命令

    chown 当我们要改变一个文件的属主,我们所使用的用户必须是该文件的属主而且同时是目标属组成员,或超级用户.只有超级用户的才能改变文件的属主. chown语法: chown  [选项]...[所有者 ...

  7. Element-ui组件--pagination分页

    一般写后台系统都会有很多的列表,有列表就相应的要用到分页,根据项目中写的几个分页写一下我对分页的理解,就当是学习笔记了. 这是Element-ui提供的完整的例子 <template>  ...

  8. 一个简单的WPF MVVM实例【转载】

    引用地址:http://blog.csdn.net/yl2isoft/article/details/20838149 1 新建WPF 应用程序WPFMVVMExample 程序结构如下图所示. 2  ...

  9. laravel-多条件查询并指定key输出

    $room = DB::table('room') ->where(function($query) use($contList){ foreach ($contList as $k=>$ ...

  10. GIL 线程池 进程池 同步 异步

    1.GIL(理论 重点)2.线程池 进程池3.同步 异步 GIL 是一个全局解释器锁,是一个互斥锁 为了防止竞争解释器资源而产生的 为何需要gil:因为一个python.exe进程中只有一份解释器,如 ...