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整 ...
随机推荐
- BAT 五路internet负载均衡
一个网上下载的bat文件 也不记得从那里下载的了 记得似乎需要管理员权限运行 依稀记得测试有效 放在这里做个记录 @echo off echo. echo ╭─────────╮ echo ╭──── ...
- DNS and Bind
DNS : 工作在应用层 DNS 作用 : 完成域名到IP的解析过程 FQDN --> IP 例如 : www.ifeng.com --> 123.103.122.24 D ...
- 易语言加壳SDK(宏标记)
转载 http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece76310508c31490797634b87834e29938448e435061 ...
- 吴裕雄--天生自然java开发常用类库学习笔记:Set接口
import java.util.HashSet ; import java.util.Set ; public class HashSetDemo01{ public static void mai ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-off
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- springboot - 返回xml error 从自定义的 ErrorController
1.概览 2.在<springboot - 返回JSON error 从自定义的 ErrorController>基础上,做如下调整: 1).新增Attribute类和Error类 pac ...
- Window Server 2019 配置篇(1)- 创建域并把本机设置成域控制器
由于这个学期的Window Server大作业是做一个服务器群,在域中创建包括DNS,DHCP,网关,更新服务器,hyper-v,自动部署等服务,所以我会把制作过程分步写在这个博客上 首先我们新建一个 ...
- 每天一点点之 uni-app 框架开发 - 页面滚动到指定位置
项目需求:在页面中,不管位于何处,点击评论按钮页面滚动到对应到位置 实现思路如下: uni.createSelectorQuery().select(".comment").bou ...
- HDU 5495:LCS
LCS Accepts: 127 Submissions: 397 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/655 ...
- dede开启会员功能
登陆后台,找到菜单里面的系统基本参数设置>会员设置>开启会员功能,选择“是”,保存即可