当前位置:网站首页>零花钱
零花钱
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);
}
边栏推荐
猜你喜欢

Alibaba 开源内网高并发编程手册

节省70%的显存,训练速度提高2倍!浙大&阿里提出在线卷积重新参数化OREPA,代码已开源!(CVPR 2022 )...

win10 校验sha256

【PCL学习笔记】点云处理常用的库和API(PCL库+Eigen)

GBJ2510-ASEMI电机专用25A整流桥GBJ2510

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

3. SAP ABAP OData 服务诊断工具 /IWFND/ERROR_LOG 的使用方法

How should small and medium-sized financial enterprises carry out disaster recovery construction?

Contribution and writing required documents - OpenHarmony developer documentation style guide

【服务器存储数据恢复】华为OceanStor某型号存储raid5硬盘故障离线,热备盘同步数据失败导致raid崩溃的数据恢复案例
随机推荐
微信公众号借助小程序云函数实现支付功能
揭秘 | 2019 To B 年度盛宴那些人和那些事
How should small and medium-sized financial enterprises carry out disaster recovery construction?
干货!如何使用仪表构造SRv6-TE性能测试环境
【微信小程序】组件使用及属性参考
专访亚信科技张桦:AntDB面向企业核心业务支撑的数据库产品
Ribbon自定义修改负载均衡
Dry goods!How to Construct SRv6-TE Performance Test Environment Using Instrumentation
[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
错排问题详解
虚拟远程桌面
数字孪生万物可视 | 联接现实世界与数字空间
Property (Property Animation Animation), the basic use of Butterknife butter knife
AI全流程开发难题破解之钥
MySQL外键约束怎么创建
闻泰科技拟收购欧菲光摄像头业务资产,或将进入苹果供应链!
图文结合纯c手写内存池
MLX90640 红外热成像仪开发笔记(九)
如何破坏单例?我说了好几种方式,面试官:没想到你真会
3. SAP ABAP OData 服务诊断工具 /IWFND/ERROR_LOG 的使用方法