当前位置:网站首页>Pocket money
Pocket money
2022-07-29 17:14:00 【seal ink】
1263: 零用钱
时间限制: 1 Sec 内存限制: 128 MB
In return for setting sales records,Farmer John决定开始每个星期给Bessie一点零花钱. FJ有一些硬币,一共有N (1 < = N < = 20)种不同的面额.Each denomination is divisible by all denominations greater than it. He wants to use the given collection of coins,每个星期至少给Bessie某个零花钱的数目C (1 < = C < = 100000000).请帮他计算他最多能支付多少个星期的零花钱.
输入
第1行: 两个由空格隔开的整数: N 和 C
第2到第N+1行: Each row has two integers representing one denomination of coins:
硬币面额V (1 < = V < = 100,000,000)
和Farmer JohnThe number of coins of that denomination ownedB (1 < = B < = 1,000,000).
输出
输出一行: 一个单独的整数,表示FJ 最多能给BessieHow many weeks to pay for at leastC的零用钱.
样例输入
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);
}
边栏推荐
猜你喜欢

【Translation】Device Manager—Intel NIC Properties Setting Advanced Options Function

RocketQA:通过跨批次负采样(cross-batch negatives)、去噪的强负例采样(denoised hard negative sampling)与数据增强(data augment

两军交锋

Query term weights, search term weighting

【Swoole系列3.2】Swoole 异步进程服务系统

揭秘 | 2019 To B 年度盛宴那些人和那些事

GMAT考什么?
![[PCL study notes] Commonly used libraries and APIs for point cloud processing (PCL library Eigen)](/img/b6/0f6113109aef776c777cb25a0ffb95.png)
[PCL study notes] Commonly used libraries and APIs for point cloud processing (PCL library Eigen)

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

Flutter动态化 | Fair 2.6.0 新版本特性
随机推荐
pjax无法生效解决办法,butterfly主题维护你的pjax
STC8h1k28六个基本实验
蓝思科技发力整机组装业务,子公司拟30亿建智能终端设备智造项目
[网络]LAN技术MSTP
zabbix email sends alert information
2020年Mobileye收入近10亿美元,EyeQ芯片出货1930万颗
【上传文件】
面试官:小伙子你来说说MySQL底层架构设计
Kubernetes 的 5 个误区
Win10 check sha256
PL5902 SOT-23-5 高效1MHz2A同步DC-DC降压调节器 百盛电子代理商
两军交锋
Chicken and rabbit in the same cage
Dry goods!How to Construct SRv6-TE Performance Test Environment Using Instrumentation
Tess4J 图片文字识别
Dynamic planning to climb the stairs
Turbine Aggregation Monitoring
如何在C语言中定义自己的数据类型?
中芯国际:禁令后全力自救,设备等待期拉长,但没有客户“离开”
[WeChat Mini Program] Component usage and attribute reference