Cf水题B - Combination
地址: https://vjudge.net/problem/27861/origin
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?
Input
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 — aiand bi (0 ≤ ai, bi ≤ 104) — the numbers, written at the top and the bottom of the i-th card correspondingly.
Output
Print the single number — the maximum number of points you can score in one round by the described rules.
Examples
2
1 0
2 0
2
3
1 0
2 0
0 2
3
Note
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.
以b为基准进行sort排序,再用一个计数器就好了。第三段写得明明白白,题意的理解很重要
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
struct node
{
int a,b;
}st[];
bool cmp(node a,node b)
{
if(a.b==b.b)
return a.a>b.a;
else
return a.b>b.b;
}
int main()
{
int n;
cin>>n;
for(int i=;i<n;i++)
cin>>st[i].a>>st[i].b;
sort(st,st+n,cmp);
int sum=,count=,all=n;
for(int i=;i<n;i++)
{
sum+=st[i].a;
count--;
all--;
count+=st[i].b;
if(count==)
break;
if(all==n)
break;
}
cout<<sum<<endl;
}
Cf水题B - Combination的更多相关文章
- 做了一道cf水题
被一道cf水题卡了半天的时间,主要原因时自己不熟悉c++stl库的函数,本来一个可以用库解决的问题,我用c语言模拟了那个函数半天,结果还超时了. 题意大概就是,给定n个数,查询k次,每次查询过后,输出 ...
- 一道cf水题再加两道紫薯题的感悟
. 遇到一个很大的数除以另一个数时,可以尝试把这个很大的数进行,素数因子分解. . 遇到多个数的乘积与另一个数的除法时,求是否能整除,可以先求每一个数与分母的最大公约数,最后若分母数字为1,则证明可整 ...
- 某5道CF水题
1.PolandBall and Hypothesis 题面在这里! 大意就是让你找一个m使得n*m+1是一个合数. 首先对于1和2可以特判,是1输出3,是2输出4. 然后对于其他所有的n,我们都可以 ...
- 一道cf水题
题意:输入数字n表示字符串中元素个数,字符串中只含有RGB三个字符,现在要求任意两个相同的字符他们的下标之差能整除3. 思路:任意两个相同的字符的下标能整除3,也就是任意三个为一组的字符串当中的字符不 ...
- 几道cf水题
题意:给你包含n个元素的数组和k种元素,要求k种元素要用完,并且每种颜色至少用一次,n个元素,如果某几个元素的值相同,这些个元素也不能染成同一种元素. 思路:如果元素个数n小于k或者值相同的元素的个数 ...
- cf水题
题意:输入多组数据,有的数据代表硬币的长宽,有的数据代表钱包的长宽,问你当这组数据代表钱包的长宽时,能不能把它前面出现的所有硬币全部装下. 思路:只要钱包的长宽大于前面出现的所有硬币的长宽就可以装下, ...
- 在$CF$水题の记录
CF1158C CF1163E update after CF1173 很好,我!expert!掉rating了!! 成为pupil指日可待== 下次要记得合理安排时间== ps.一道题都没写的\(a ...
- 寒假第一发(CF水题两个)
地址http://codeforces.com/contest/799 A. Carrot Cakes In some game by Playrix it takes t minutes for a ...
- CF 628B New Skateboard --- 水题
CD 628B 题目大意:给定一个数字(<=3*10^5),判断其能被4整除的连续子串有多少个 解题思路:注意一个整除4的性质: 若bc能被4整除,则a1a2a3a4...anbc也一定能被4整 ...
随机推荐
- SQLlite的olestr
关于SQLite的connection string说明:http://www.connectionstrings.com/sqlite/ SQLite GUI客户端列表:http://www.sql ...
- POJO,JavaBean,entity的理解
POJO本质是就是JavaBean JavaBean JavaBean实际上是指一种特殊的Java类,它通常用来实现一些比较常用的简单功能,并可以很容易的被重用或者是插入其他应用程序中去.所有遵循“一 ...
- CSS屏幕适配尺寸样式
/* 大屏幕 :大于等于1200px*/@media (min-width: 1200px) { ... } /*默认*/@media (min-width: 980px){...} /* 平板电脑和 ...
- hibernate字段值无法保存
通过hibernate对Blogstorage对象进行保存操作,filepath属性的值无论设置多少遍都保存不进去 后来发现是 Blogstorage.hbm.xml 里面根本没有配置filepath ...
- FULLTEXT INDEX全文索引
给现有的wxinfo表的sourceUrl 字段创建全文索引 ALTER TABLE wxinfo ADD FULLTEXT INDEX sourceUrl (sourceUrl) 创建全文索引前: ...
- 剑指offer - 栈的压入弹出序列 - JavaScript
题目描述 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否可能为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列 1,2,3,4,5 是某栈的压入顺序,序列 4,5,3,2,1 ...
- 十四、JavaScript之不同类型变量相加
一.代码如下 二.效果如下 <!DOCTYPE html> <html> <meta http-equiv="Content-Type" conten ...
- 分享一个php加密字符串类。
class base64{ /** * 加密字符串 * @access static * @param string $data 字符串 * @param string $key 加密key * @r ...
- Elasticsearch 集群 - 健康检查
章节 Elasticsearch 基本概念 Elasticsearch 安装 Elasticsearch 使用集群 Elasticsearch 健康检查 Elasticsearch 列出索引 Elas ...
- hdu4632 Palindrome subsequence 回文子序列个数 区间dp
Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65535 K (Java/ ...