贪心 Codeforces Round #109 (Div. 2) B. Combination

 

题目传送门

 1 /*
 2     贪心:按照能选的个数和点数降序排序,当条件不符合就break,水题啊!
 3 */
 4 #include <cstdio>
 5 #include <algorithm>
 6 #include <cstring>
 7 #include <cmath>
 8 using namespace std;
 9 
10 const int MAXN = 1e3 + 10;
11 const int INF = 0x3f3f3f3f;
12 struct Card
13 {
14     int a, b;
15 }card[MAXN];
16 
17 bool cmp(Card x, Card y)
18 {
19     if (x.b == y.b)    return x.a > y.a;
20     return x.b > y.b;
21 }
22 
23 int main(void)        //Codeforces Round #109 (Div. 2) B. Combination
24 {
25 //    freopen ("B.in", "r", stdin);
26 
27     int n;
28     while (scanf ("%d", &n) == 1)
29     {
30         for (int i=1; i<=n; ++i)
31         {
32             scanf ("%d%d", &card[i].a, &card[i].b);
33         }
34         sort (card+1, card+1+n, cmp);
35 
36         int ans = 0;    int res = 1;    int cnt = 1;
37         for (int i=1; i<=n; ++i)
38         {
39             res += card[i].b - 1;    ans += card[i].a;
40             cnt = cnt - 1 + card[i].b;
41             if (cnt <= 0)    break;
42             if (res <= 0)    break;
43         }
44 
45         printf ("%d\n", ans);
46     }
47 
48     return 0;
49 }

 

转载于:https://www.cnblogs.com/Running-Time/p/4566298.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值