zoukankan      html  css  js  c++  java
  • [AtCoder AGC27A]Candy Distribution Again

    题目大意:把$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
    ", ans);
    	return 0;
    }
    

      

  • 相关阅读:
    Xcode Debugging
    GCD 深入理解
    iOS GCD编程
    iOS 面试之Block
    iOS SDWebImage 实现原理
    Block 初试
    通讯录
    UIScrollerView 的简单使用
    NSSet NSMutableSet的简单使用
    code
  • 原文地址:https://www.cnblogs.com/Memory-of-winter/p/9771793.html
Copyright © 2011-2022 走看看