Codeforces 609A USB Flash Drives 【水题】
来源:互联网 发布:thinkphp商城免费源码 编辑:程序博客网 时间:2024/05/20 11:22
Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, ..., an megabytes. The file size is equal to m megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.
The first line contains positive integer n (1 ≤ n ≤ 100) — the number of USB flash drives.
The second line contains positive integer m (1 ≤ m ≤ 105) — the size of Sean's file.
Each of the next n lines contains positive integer ai (1 ≤ ai ≤ 1000) — the sizes of USB flash drives in megabytes.
It is guaranteed that the answer exists, i. e. the sum of all ai is not less than m.
Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.
35213
2
36232
3
25510
1
In the first example Sean needs only two USB flash drives — the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second.
题意:给你一个m大的总内存和n个USB快闪驱动器,问你至少需要多少个USB快闪驱动器才能装满或者超过总内存。
排下序,模拟就好了。
AC代码:
#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <set>#include <vector>#define INF 0x3f3f3f3f#define eps 1e-8#define MAXN (100+10)#define MAXM (100000)#define Ri(a) scanf("%d", &a)#define Rl(a) scanf("%lld", &a)#define Rf(a) scanf("%lf", &a)#define Rs(a) scanf("%s", a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%.2lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define W(a) while(a--)#define CLR(a, b) memset(a, (b), sizeof(a))#define MOD 1000000007#define LL long long#define lson o<<1, l, mid#define rson o<<1|1, mid+1, r#define ll o<<1#define rr o<<1|1using namespace std;int a[MAXN];int main(){ int n, m; Ri(n); Ri(m); for(int i = 0; i < n; i++) Ri(a[i]); sort(a, a+n); int ans = 0; for(int i = n-1; i >= 0; i--) { ans++; m -= a[i]; if(m <= 0) break; } Pi(ans); return 0;}
- Codeforces 609A USB Flash Drives 【水题】
- CodeForces 609A USB Flash Drives
- CodeForces 609 A. USB Flash Drives(贪心)
- A. USB Flash Drives
- CF 609A USB Flash Drives
- USB Flash Drives(水题,排序)
- 【Educational Codeforces Round 3 A】【水题 排序】USB Flash Drives 最少数量U盘存储m大小文件
- USB Flash Drives
- USB Flash Drives
- USB Flash Drives
- Usb Flash Drives - backtrack 5
- 2017寒假集训-小题训练1:D - USB Flash Drives
- ivman does not mount usb hard drives
- How to disable USB Drives 如何禁用USB优盘
- Create bootable USB drives 制作iso转usb的启动盘
- Install Ubuntu 10.04 LTS on a USB Flash Memory
- Install CentOS 5 to a USB Flash Drive in Windows
- How to Configure Hard Disk Drives on a CEPC
- git 及 tortoisegit
- 在C++中获取内存大小
- 在android下使用i2c tools
- 安卓屏幕适配(2015终极版)
- Android多媒体之 wav和amr的互转
- Codeforces 609A USB Flash Drives 【水题】
- 程序人生(一)开始
- Ceph块存储性能预估与测试
- gradle配置
- 一道面试题 设计4个线程,其中两个每次对j增加1,另外两个对j每次减少1。循环100次。
- android中 init()
- 短信验证的实现(基于云之讯短信验证SDK)
- c语言项目感受
- 响应式布局