CodeForces 155B - Combination(贪心)

STM32开发实战:从嵌入式系统到硬件控制 | 你必须得会 🏆本文收录于「编程与技术实战」专栏,此专栏涵盖了C/C++编程、人工智能、数据结构、机器学习等技术领域的内容,助你早日登顶实现财富自由🚀;同时,欢迎大家关注&&收藏&&订阅!持续更新中,up!up!up!! 阅读详情

B. Combination
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 — ai and 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.

Sample test(s)
input
2
1 0
2 0
output
2
input
3
1 0
2 0
0 2
output
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.



================================

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;
}


多源异构数据融合(Kaggle+Google Trends联合分析) 本文详细介绍了如何利用Python实现多源异构数据融合,以Kaggle电商销售数据与Google Trends搜索指数为例,展示了数据清洗、预处理、时间对齐、数据合并、相关性分析、回归建模和可视化全过程。数据预处理与内存优化通过分块加载、数据类型转换和缺失值处理,有效降低了大规模数据在内存中的占用,并确保数据质量。时间对齐与数据融合策略采用重采样与内连接方法对齐不同数据源的时间维度,实现了高质量数据的融合,为后续联合分析奠定基础。模型构建与分析。 阅读详情

相关推荐

最新小旋风蜘蛛池X6.21解密版+绕过授权带教程

介绍: 1.站群管理:用你的域名在这里添加网站 2.站点优化:站点互链,内容优化 2.系统设置:开启蜘蛛池 3.采集管理(可开启自动采集) 4.缓存设置:推荐开启tkd缓存 其他的用户根据自己的实际情况后台进行配置,通常以下: 1.后台首页(这里显示系统的大致概况) 2.系统设置:蜘蛛池的基本设置(访问开关、跳转、统计等等) 3.站群管理: 1.网站管理(用你的域名在这里添加网站) 2.模型管理(可构建不同类型站点:电影、文章、论坛等等) 3.TKDB调用模板(即:title、keywords、descri

百度SEO程序下载 2937

Codeforces Round #109 (Div. 2)——B

B. Combination time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ilya plays a card game by the following rule

Learn as if you were to live forever 593

AMCL代码详解(六)amcl中的重采样

每次都从w1左边的竖线开始转,显而易见,转到w1的概率为0-w1之间的随机数,转到w2的概率为w1到w1+w2之间的随机数,转到w3的概率为w1+w2到w1+w2+w3之间的随机数,后面的依次类推。当某个粒子的权值较大的时候,产生的随机数落在相应区间的概率就会增大,从而实现了对权值大粒子的多次复制,权值小的粒子的剔除。可以看出,在整个重采样的过程中,粒子进行了两次种情况的刷新,一种是随机生成的新的粒子,一种是对原来的粒子的复制。得到的值越大,说明粒子的权重越小,当前粒子的可信度比较小,需要重采样粒子。

YiYeZhiNian的博客 1579

Codeforces 155B Combination

题意: 给你n张牌,每张牌有a[i]、b[i],分别表示可以获得的分数和可以获得的取牌次数,问在一开始只能取一次的情况下能获得的最大分数是多少。 思路: 由于这里的a[i]、b[i]都是正整数,那么当然取得牌越多分数越大,所以就有了贪心的策略,即先按b从大到小排,若b一样则a大的先排。 #include #include using namespace std; const int MA

w446506278的博客 352

大模型事件抽取学习——论文学习笔记《LLMs Learn Task Heuristics from Demonstrations:......》

本篇博客介绍一篇发表在2024 ACL main上的文章:《LLMs Learn Task Heuristics from Demonstrations: A Heuristic-Driven Prompting Strategy for Document-Level Event Argument Extraction》 方向:大模型事件抽取 本篇博客为个人阅读论文的总结与笔记,在这里进行简单的分享 论文链接:https://arxiv.org/abs/

weixin_53751318的博客 1852

如何让Arduino IDE支持你手里的STM32 nucleo开发板

Arduino IDE开发环境在默认情况下不支持STM32 NUCLEO开发板,只有通过添加附加开发板管理包才能使用。目前为止,只有一部分板子支持使用Arduino IDE开发环境进行开发,分别是 Nucleo F207ZG, Nucleo F429ZI, Nucleo F030R8, Nucleo F091RC, Nucleo F103RB, Nucleo F303RE, Nucl...

mzw72188552的专栏 8972

155B. Combination 解题报告

B. Combination time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ilya plays a card game by the following rules. ...

weixin_30364147的博客 164

我终于停止写 JUnit 了!用 JavaParser + GPT-4 自动生成 90% 覆盖率的单元测试

本文介绍了一种基于JavaParser和GPT-4的智能单元测试生成方案。针对开发者在单元测试编写中面临的繁琐、无聊和硬指标等问题,提出通过AST语法树分析代码结构,提取关键信息后生成精准提示词,再调用GPT-4自动生成高质量的单元测试代码。文章详细阐述了技术原理、实现步骤(包括JavaParser解析、上下文感知提示词构建和GPT-4调用),并展示了该方法能自动识别依赖、Mock对象和覆盖边界条件,显著提升测试效率。同时指出了在复杂数据结构、私有方法测试等方面的局限性,最终强调这种技术组合可以解放开发者,

BUG猿的博客 1129

codeforces 156B Suspects 暴力

Suspectstime limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output As Sherlock Holmes was investigating a crime, he identified n suspects. He knows fo

enamor_AC的博客 955

Apollo 9.0 速度非线性规划算法 – piecewise jerk speed nonlinear optimizer Ⅰ

二次规划的速度规划算法(PiecewiseJerkSpeedOptimizer)的存在两个问题: 这里以一张图来说明上面的问题,假设存在一个实际限速区间(或曲率很大需要降速的区间)[S1, S2],PiecewiseJerkSpeedOptimizer的做法是根据动态规划的st曲线(黑色),找到具体的时间区间[T1, T2],然后对区间[T1, T2]内所有的点施加约束或惩罚。但是二次规划平滑后的曲线(黄色)发生了变化,那么限速区间[S1, S2]对应的时间区间[T1, T2]也发生了变化,所以实际应该是对

WaiNgai 333

国科大学习资料--数据挖掘(刘莹)--第三章习题及参考答案

国科大学习资料–数据挖掘(刘莹)–第三章习题及参考答案 国科大学习资料–数据挖掘(刘莹)–第三章习题及参考答案 国科大学习资料–数据挖掘(刘莹)–第三章习题及参考答案 第 3 章分类与回归 3.1简述决策树分类的主要步骤。 答:决策树生成的过程如下: (1)对数据源进行数据预处理, 得到训练集和测试集; (2)对训练集进行训练; (3)对初始决策树进行树剪枝; (4)由所得到的决策树提取分类规则; (5)使用测试数据集进行预测,评估决策树模型; 3.2给定决策树,选项有:(1)将决策树转换成规则,然后对结果

无名何许人的博客 3092

codeforces B. Combination(贪心)

题意:有N张卡牌,每张卡牌有两个值a和b,a代表能获得的点数,b代表拿了这张卡牌后还能拿多少张卡牌,拿了一张卡牌就丢掉一张卡牌。求能获得的最大点数。 分析:对b从大到小排序,若b相等,对a从大到小排序,然后一张张拿,点数相加就可以。 #include #include #include #include using namespace std; //int a[1005],b[1005]; s

onthewaytotop的博客 335

【OpenFOAM】-olaFlow-算例10-wavemakerTank

采用 Flap和Piston两种方式的动网格进行造波

ou_no的博客 2167

贪心 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 namesp...

weixin_34345560的博客 140

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Educational Codeforces Round 108 (Rated for Div. 2)

Educational Codeforces Round 108A - Red and Blue BeansB - The Cake Is a LieC - Berland RegionalD - Maximum Sum of Products A - Red and Blue Beans 题目链接 答案 #include <iostream> #include<bits/stdc++.h> #define ll long long #define mem(a,b) memset(a

qq_45830025的博客 280

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

Codeforces Round #109 (Div. 1)B 数论

//两个数如果不是互质,那么它们一定有一个质数因子 //用vec存入2到n的所有的质数因子 //用vis存入有该因子的数是否读入 //处理时只需要维护vis这个数组就行 #include #include #include #include using namespace std ; const int maxn  =  100010 ; vector vec[maxn];

ijbuhv的专栏 713

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

codeforce补题记录

B2. Palindrome Game (hard version) The only difference between the easy and hard versions is that the given string s in the easy version is initially a palindrome, this condition is not always true for the hard version. A palindrome is a string that reads

hexiaoguozhima的博客 460

SCUT 2014 春季选拔第一场个人题解

第一场 A.回文串 1000ms   /  65536KB   /   C, C++ or JAVA Author: dovegx   /   Editor: dovegx Description 据说字符串都是很难的,可是芳姐最喜欢了,最近他迷上了回文字符串,回文串正着读和反着读是一样的,比如 abba, aaaa都是回文串, abbc不是回文串。芳姐想知道如果把整个字符串拆散重新组合

代码小屋 1216

小a和小b一起玩一个游戏,两个人一起抛掷一枚硬币,正面为H,反面为T。两个人把抛到的结果写成一个序列。如果出现HHT则小a获胜,游戏结束。如果HTT出现则小b获胜。问a获胜的概率?

小a和小b一起玩一个游戏,两个人一起抛掷一枚硬币,正面为H,反面为T。两个人把抛到的结果写成一个序列。如果出现HHT则小a获胜,游戏结束。如果HTT出现则小b获胜。小a想问一下他获胜的概率是多少?情况分析: 设a获胜的概率为x,则: 上分支a的概率为:1/2*(1/2+1/4+…+1/(z^n-1))=1/2 下分支a的概率为:1/2*1/2*x 于是:x=1/2+x*1/4->x=2/3

Skyline 8510

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...

weixin_30819085的博客 139

POJ 题目1306 Combinations(排列组合)

Combinations Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8701   Accepted: 4047 Description Computing the exact number of ways that N things can be taken

Jogging_Clown 1162

Combination Sum IV中两种JAVA动态规划解法的不同

leetcode题目:https://leetcode.com/problems/combination-sum-iv/#/description Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add u

wuwuzhixiang的博客 543

2633. Combination

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 o...

乌药ice 350

组合(Java实现)

题目: 求解n个元素的组成的大小为m的组合 思路: 假设我们想在长度为n的字符串中求m个字符的组合。 我们先从头扫描字符串的第一个字符。 针对第一个字符,我们有两种选择: 一是把这个字符放到组合中去,接下来我们需要在剩下的n-1个字符中选取m-1个字符; 二是不把这个字符放到组合中去,接下来我们需要在剩下的n-1个字符中选择m个字符。这两种选择都很容易用递归实现。 思路讲完了,直接...

a754112602的博客 2538

01(CodeforcesB水平)CQU新生周末狂欢赛F - Smile House

F - Smile House Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 155B Description Ilya plays a card game by the followi

阿里巴巴算法工程师 625

CodeForces 109B Lucky Probability

题意是由4和7组成的数字称为lucky number,给你两个区间 在这两个区间里随机选两个数字作为左区间和右区间。问你在这个区间中lucky number个数为k个的期望为多少。 这题的思路就是先预处理出来所有的lucky number,遍历每个lucky number。 算出符合提议的情况有多少种。然后除以情况总数就好了。 AC代码: #include #include #inc

ACMan 613
上一篇: CodeForces 157B - Trace
下一篇: CodeForces 165C - Another Problem on Strings
coco430
博客等级 码龄14年 9粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值