当前位置:网站首页>零花钱
零花钱
2022-07-29 16:00:00 【封子墨】
1263: 零用钱
时间限制: 1 Sec 内存限制: 128 MB
作为创造销售纪录的回报,Farmer John决定开始每个星期给Bessie一点零花钱。 FJ有一些硬币,一共有N (1 < = N < = 20)种不同的面额。每一个面额都能整除所有比它大的面额。 他想用给定的硬币的集合,每个星期至少给Bessie某个零花钱的数目C (1 < = C < = 100000000)。请帮他计算他最多能支付多少个星期的零花钱。
输入
第1行: 两个由空格隔开的整数: N 和 C
第2到第N+1行: 每一行有两个整数表示一个面额的硬币:
硬币面额V (1 < = V < = 100,000,000)
和Farmer John拥有的该面额的硬币数B (1 < = B < = 1,000,000).
输出
输出一行: 一个单独的整数,表示FJ 最多能给Bessie支付多少个星期至少为C的零用钱。
样例输入
3 6
10 1
1 100
5 120
样例输出
111
#include<stdio.h>
#include<algorithm>
using namespace std;
struct Money {
int The_price;
int The_number;
};
int cmp(Money a,Money b) {
return a.The_price<b.The_price;
}
int main() {
int N,C,sum=0,num;
bool judge=true;
scanf("%d %d",&N,&C);
struct Money money[N];
for(int i=0; i<N; i++)
scanf("%d %d",&money[i].The_price,&money[i].The_number);
sort(money,money+N, cmp);
for(num=N-1; num>=0; num--)
if(money[num].The_price>=C)
sum+=money[num].The_number;
else break;
while(judge) {
judge=false;
int t=C;
for(int i=num; i>=0; i--) {
while(t>money[i].The_price&&money[i].The_number>0) {
t-=money[i].The_price;
money[i].The_number--;
}
}
for(int i=0; i<=num; i++) {
while(t>0&&money[i].The_number>0) {
t-=money[i].The_price;
money[i].The_number--;
}
}
if(t<=0) {
judge=true;
sum++;
}
}
printf("%d\n",sum);
}
边栏推荐
- 分布式前修课:MySQL实现分布式锁
- 百面量化金融
- 如何写好设计文档
- 稳步向前不忘初心,沃尔沃的安全感来自公众的认可
- 地平线获得舜宇集团战略投资并与舜宇智领签署战略合作协议
- uni-app判断平台开发环境和生产环境
- 基于全志D1-H和XR806的名贵植物监控装置
- CRM如何帮助企业营销获客
- 旭硝子龟尾工厂3月起将减少30%玻璃基板供应!TCL华星、友达、群创、惠科均受影响
- Moving forward steadily without forgetting the original intention, Volvo's sense of security comes from the public's recognition
猜你喜欢

【微服务】 微服务学习笔记二:Eureka注册中心的介绍及搭建

Android Studio 实现登录注册-源代码 (连接MySql数据库)

BUUCTF——MISC(流量分析)

MySQL数据库安装配置保姆级教程(以8.0.29为例)有手就行

【服务器存储数据恢复】华为OceanStor某型号存储raid5硬盘故障离线,热备盘同步数据失败导致raid崩溃的数据恢复案例

双非渣渣的上岸之路!备战 60 天,三战滴滴侥幸收获 Offer

This article penetrates the architecture design and cluster construction of the distributed storage system Ceph (hands-on)

设置工作模式与环境

6月阿里遭拒,90天深造357页微服务手册,获京东offer

干货!如何使用仪表构造SRv6-TE性能测试环境
随机推荐
如何在C语言中定义自己的数据类型?
2020年Mobileye收入近10亿美元,EyeQ芯片出货1930万颗
大规模线上应用TiDB会遇到的坑,本文都帮你排除好了
中国大学慕课mooc答题/自动播放脚本(domooc)使用教程
Kubernetes 的 5 个误区
sorting and searching 二分查找法
Twin all things digital visual | join the real world and the digital space
Practice of Weibo Advertising Operation and Maintenance Technology Supporting Ten Billions of Requests
地平线获得舜宇集团战略投资并与舜宇智领签署战略合作协议
Linux environment redis complete configuration and startup command
mysql的sql分页查询语句怎么写_sql 分页查询语句(mysql分页语句)「建议收藏」
pjax无法生效解决办法,butterfly主题维护你的pjax
Google Play 政策更新 | 2022 年 7 月
Detailed evaluation of Renesas RZ/G2L processor
旭硝子龟尾工厂3月起将减少30%玻璃基板供应!TCL华星、友达、群创、惠科均受影响
Moving forward steadily without forgetting the original intention, Volvo's sense of security comes from the public's recognition
中国厂商统治印度智能手机市场,份额提升至77%
zabbix邮件发送告警信息
Alibaba 开源内网高并发编程手册
[Server Storage Data Recovery] A data recovery case of a RAID 5 crash caused by the failure of a certain model of Huawei OceanStor storage RAID 5 hard disk and the failure to synchronize data with the