CodeForces 155B - Combination(贪心)
来源:互联网 发布:centos安装wget命令 编辑:程序博客网 时间:2024/05/21 19:28
Ilya plays a card game by the following rules.
A player has several cards. Each card contains two non-negative integers inscribed, one at the top of the card and one at the bottom. At the beginning of the round the player chooses one of his cards to play it. If the top of the card contains number ai, and the bottom contains number bi, then when the player is playing the card, he gets ai points and also gets the opportunity to play additional bi cards. After the playing the card is discarded.
More formally: let's say that there is a counter of the cards that can be played. At the beginning of the round the counter equals one. When a card is played, the counter decreases by one for the played card and increases by the number bi, which is written at the bottom of the card. Then the played card is discarded. If after that the counter is not equal to zero, the player gets the opportunity to play another card from the remaining cards. The round ends when the counter reaches zero or the player runs out of cards.
Of course, Ilya wants to get as many points as possible. Can you determine the maximum number of points he can score provided that you know his cards?
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of cards Ilya has.
Each of the next n lines contains two non-negative space-separated integers — ai and bi (0 ≤ ai, bi ≤ 104) — the numbers, written at the top and the bottom of the i-th card correspondingly.
Print the single number — the maximum number of points you can score in one round by the described rules.
21 02 0
2
31 02 00 2
3
In the first sample none of two cards brings extra moves, so you should play the one that will bring more points.
In the second sample you should first play the third card that doesn't bring any points but lets you play both remaining cards.
================================
a是分数,b是能再玩的卡片数,贪心,对卡片数排序,先玩能得卡片数多的必然能得到最多的分数
#include<iostream>#include<cstdio>#include <algorithm>using namespace std;struct card{ int top; int bot;}s[1111];bool cmp(card a,card b){ if(a.bot==b.bot) return a.top>b.top; return a.bot>b.bot;}int main(){ int n,cnt=1,ans=0; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d%d",&s[i].top,&s[i].bot); } sort(s,s+n,cmp); for(int i=0;i<n;i++) { if(cnt) { ans+=s[i].top; cnt--; cnt+=s[i].bot; } else break; } printf("%d\n",ans); return 0;}
- CodeForces 155B - Combination(贪心)
- codeforces B. Combination(贪心)
- Codeforces 155B Combination
- CodeForceS#276-B(贪心)
- codeforces A. Combination Lock 贪心
- CodeForces 496B Secret Combination
- CodeForces-496B Secret Combination
- codeforces 496B Secret Combination
- Codeforces Round #283 (Div. 2)---B. Secret Combination (暴力)
- Codeforces 496B Secret Combination(最小表示法)
- B. Secret Combination codeforces-problem-496B
- CodeForces 378B Semifinals(贪心)
- Codeforces 384B Multitasking(贪心)
- Codeforces 416B Art Union(贪心)
- codeforces 158B Taxi(贪心小水题)
- codeforces 158B Taxi (贪心)
- Codeforces 3B.Lorry(贪心,排序)
- CodeForces 384B Multitasking(大概是贪心)
- CodeForces #200(Div.2) A. Magnets
- 大家思考一道题:已知二叉树的前序和后序,能确定多少个二叉树?
- toj1726 World Cup Noise
- HadoopHbaseZookeeper集群
- 单元测试OCUnit+xctool
- CodeForces 155B - Combination(贪心)
- php中echo<<<的应用
- android整合--屏幕旋转触发事件
- Java 正则表达式
- poj 1731 字典序全排列
- HDOJ, 杭电1108, 最小公倍数题目,简单的数学题。。。。
- Handler sendMessage 与 obtainMessage (sendToTarget)比较
- leetcode之Remove Duplicates from Sorted Array
- ImageMagick 下合并图片