Codeforces Round #287 (Div. 2)A(排序)
来源:互联网 发布:js获取页面高度赋给div 编辑:程序博客网 时间:2024/06/05 16:58
题目链接:http://codeforces.com/contest/507/problem/A
解题思路:
排个序就出来了。
完整代码:
#include <algorithm>#include <iostream>#include <cstring>#include <complex>#include <cstdio>#include <string>#include <cmath>using namespace std;typedef long long LL;const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const double EPS = 1e-9;const double PI = acos(-1.0); //M_PI;struct node{ int w , id;}k[10001];bool cmp(node a , node b){ return a.w < b.w;}int res[10001];int main(){ #ifdef DoubleQ freopen("in.txt","r",stdin); #endif std::ios::sync_with_stdio(false); std::cin.tie(0); int n , key; while(cin >> n >> key) { for(int i = 1 ; i <= n ; i ++) { cin >> k[i].w; k[i].id = i; } memset(res , 0 , sizeof(res)); sort(k + 1 , k + n + 1 , cmp); int cnt = 0; for(int i = 1 ; i <= n ; i ++) { if(key >= k[i].w) { key -= k[i].w; res[cnt++] = k[i].id; } if(key <= 0) break; } cout << cnt << endl; if(cnt == 0) continue; for(int i = 0 ; i < cnt - 1 ; i ++) cout << res[i] << " "; cout << res[cnt - 1] << endl; }}
0 0
- Codeforces Round #287 (Div. 2)A(排序)
- [Codeforces] Round #287 (Div. 2) A、B
- Codeforces Round #287 (Div. 2) A、B、C、D、E
- A Amr and Music( Codeforces Round #287 (Div. 2))
- Codeforces Round #287 (Div. 2) A B C
- Codeforces Round #287 (Div. 2)A,B,C,D,E
- Codeforces Round #287 (Div. 2)(A,B题)
- Codeforces Round #287 (Div. 2) A. Amr and Music
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #174 (Div. 2) Problem A
- Codeforces Round #173 (Div. 2) A.Bit++
- Codeforces Round #181 (Div. 2) A题
- Codeforces Round #184 (Div. 2) A题
- Codeforces Round #185 (Div. 2)--A,B
- Codeforces Round #172 (Div. 2) A题
- Codeforces Round #166 (Div. 2) A题
- Codeforces Round #132 (Div. 2) A题
- Codeforces Round #131 (Div. 2) A题
- UVALive 3029 City Game 悬线法求最大子矩阵面积 dp
- google maps API 替换更换为 baidu maps API
- Minimizing maximizer - POJ 1769 dp+线段树
- hdu-1114 Piggy-Bank
- Backgroud-Master Data-Sales Org.
- Codeforces Round #287 (Div. 2)A(排序)
- Eclispe中的Junit3快速起步
- Codeforces GYM 100548 F - Color 2014-2015 ACM-ICPC, Asia Xian Regional Contest
- poj 3045 Cow Acrobats 贪心
- 1001Jump and Jump...
- LeetCode 3Sum Closest
- MQTT简介
- 黑马程序员Android第55期—— XML 实例一
- C编译器剖析_2.2 词法分析