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整 ...
随机推荐
- 五、Vue:使用axios库进行get和post、用拦截器对请求和响应进行预处理、Mock(数据模拟)
一.axios [应用]进行请求和传表单 [axios中文档]:https://www.kancloud.cn/yunye/axios/234845 [vue-axios]:https://cn.vu ...
- (三)微信小程序配置
小程序官方文档 全局配置
- nginx安全参数
Strict-Transport-Security Strict-Transport-Security,简称 HSTS.该响应头用于标识浏览器用 HTTPS 替代 HTTP 的方式去访问目标站点. 我 ...
- Shell脚本之awk篇
目录:一.概述二.awk基本语法格式三.awk基本操作四.awk条件及循环语句五.awk函数六.awk演示示例(源自于man手册) 一.概述 1. 产品概述: awk是一种编程语言,用于在linux/ ...
- HDU 5504:GT and sequence
GT and sequence Accepts: 95 Submissions: 1467 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- maven手动安装ojdbc6.jar包到本地仓库
需要jar文件 ojdbc6.jar jar下载地址1 下载地址2 本地执行: mvn install:install-file -Dfile=D:/ojdbc6.jar -DgroupId=co ...
- 解决Java POI 导出Excel时文件名中文乱码,兼容浏览器
String agent = request.getHeader("USER-AGENT").toLowerCase(); response.setContentType(&quo ...
- 深度解析高分Essay写作组成部分
很多留学生在国外呆了好几个学期对于怎么写Essay还是不太了解,今天小编大致总结了以下一些技巧,相信同学们可以尝试着自己完成一篇Essay写作!一起来看看吧! 与你的导师沟通 你的导师对于你的Essa ...
- MyBatis的初始化过程。
对于任何框架而言,在使用前都要进行一系列的初始化,MyBatis也不例外.本章将通过以下几点详细介绍MyBatis的初始化过程. 1.MyBatis的初始化做了什么 2. MyBatis基于XML配置 ...
- 在MFC做DLL动态链接库时,使用boost,出现断言错误
建立的MFC DLL工程中有使用boost::thread,就会发生compile正常但是一程式执行或者直接编辑就出現ASSERT错误. 错误位置:dllinit.cpp,Line: 587,ASSE ...