#106 (div.2) A. Business trip
来源:互联网 发布:投资入门知乎 编辑:程序博客网 时间:2024/05/23 05:09
1.题目描述:点击打开链接
2.解题思路:本题利用贪心法解决。首先对数组排序,由大到小选择,恰好大于等于k时候停止即可。如果全部相加仍然小于k,则无解。
3.代码:
#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<algorithm>#include<string>#include<sstream>#include<set>#include<vector>#include<stack>#include<map>#include<queue>#include<deque>#include<cstdlib>#include<cstdio>#include<cstring>#include<cmath>#include<ctime>#include<functional>using namespace std;#define me(s) memset(s,0,sizeof(s))typedef long long ll;typedef unsigned int uint;typedef unsigned long long ull;typedef pair <int, int> P;const int N=20;int a[N];int k;int main(){ while(~scanf("%d",&k)) { for(int i=1;i<=12;i++) scanf("%d",&a[i]); sort(a+1,a+12+1); int st=12,sum=0; int ans=-1; while(sum<k&&st>=1) { sum+=a[st--]; } if(sum>=k&&st>=0)ans=12-st; printf("%d\n",ans); }}
0 0
- #106 (div.2) A. Business trip
- A. Business trip
- Codeforces 149A Business trip【水题】
- Codeforces Round #441 (Div. 2)A. Trip For Meal
- Some useful techiques when you are on a business trip
- Business trip to BeiJing_0921
- Codeforces Round #396(Div. 2)E. Mahmoud and a xor trip【二进制拆位+Dfs处理】
- Codeforces Round #396(Div. 2)E. Mahmoud and a xor trip
- Codeforces Round #396 (Div. 2) E. Mahmoud and a xor trip
- Codeforces Round #396 (Div. 2) E. Mahmoud and a xor trip dfs 按位考虑
- Codeforces Round #441 (Div. 2)A. Trip For Meal模拟水题
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) A. Trip For Meal
- Mishka and trip(CF #365 Div. 2)
- Codeforces Round #396 (Div. 2) E. Mahmoud and a xor trip(树形dp+二进制按位拆分)
- Codeforces#365 (Div.2) Mishka and trip【思维】
- Codeforces Round #365 (Div. 2) Mishka and trip
- Codeforces Round #365 (Div. 2) B. Mishka and trip
- Codeforces Round #365 (Div. 2) Mishka and trip
- Swift入门(三)——元组(Tuple)
- Swift-ReactiveCocoa3.0(二)SignalProducer 2
- 7-30
- Objective-C Runtime 底层机制
- HTML 标签列表(1)
- #106 (div.2) A. Business trip
- iOS基础--数据解析(XML)
- cvCanny函数中, 高低阈值自适应计算方法
- 用happen-before规则重新审视DCL
- PAT乙级 1017. A除以B
- Entity Framework
- Android类说明---Scroller
- 恰好有N个因子的最小正整数M
- EventProxy使用学习笔记