poj--2782
2015-08-25 09:55
225 查看
题意:
贪心,排序后大数与小数相加
具体代码:
View Code
贪心,排序后大数与小数相加
具体代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> using namespace std; #define maxn 100005 int n, m; int f[maxn]; int cmp(int a, int b) { return a > b; } int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", &f[i]); sort(f, f + n, cmp); int l = 0, r = n - 1; while (l <= r) { if (f[l] + f[r] <= m) r--; l++; } printf("%d\n", l); return 0; }
View Code
相关文章推荐
- poj--2608
- poj--2782
- poj--2608
- poj--3086
- poj--3173
- poj-3627
- poj-3438
- poj-3302
- 辽宁省赛——杨鲁斯卡尔专场-J
- 辽宁省赛——杨鲁斯卡尔专场 -F
- 临时变量作为非const的引用进行参数传递引发的编译错误
- Spark技术实战之1--KafkaWordCount
- 【HDU3038】【加权并查集】
- 临时变量作为非const的引用进行参数传递引发的编译错误
- HDU 2844+POJ 1014 +FZU 1432详解(多重背包&&二进制优化)
- POJ 3126 Prime Path (BFS)
- 揭秘谷歌网络基础设施十年演变过程
- vijos1098:合唱队形
- 5.5 运算符问题
- zzuli训练赛_05_13-K