B1. Bouquet (Easy Version)

在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述
用map存下所有数的值和次数,然后直接遍历map即可

#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#define x first
#define y second
#define int long long 
using namespace std;
int t, n, m;
int w[200005];
signed main()
{
	cin >> t;
	while (t--) {
		int mmax = 0;
		map<int, int>mp;
		cin >> n>>m;
		for (int i = 1; i <= n; i++) {
			cin >> w[i]; 
			mp[w[i]]++;
		}
		for (auto tt:mp)
		{
			int a = min(tt.y, m / tt.x);
			int next = tt.x + 1;
			int b = 0;
			if (mp.count(next))
			{
				b = mp[next];
			}
			for (int i = 0; i <= a; i++)
			{
				int j = (m - i * tt.x) / next;
				j = min(j, b);
				mmax = max(mmax, i * tt.x + j * next);
			}
		}
		cout << mmax << endl;
	}
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的购买多种花束的代码示例: ```python # 花束的类定义 class Bouquet: def __init__(self, name, price): self.name = name self.price = price # 主程序 def main(): # 定义几个花束 bouquet1 = Bouquet("玫瑰花束", 99.9) bouquet2 = Bouquet("康乃馨花束", 89.9) bouquet3 = Bouquet("百合花束", 79.9) # 输出花束信息 print("欢迎光临我们的花店!") print("我们有以下花束可供选择:") print("1. " + bouquet1.name + ",价格:" + str(bouquet1.price) + "元") print("2. " + bouquet2.name + ",价格:" + str(bouquet2.price) + "元") print("3. " + bouquet3.name + ",价格:" + str(bouquet3.price) + "元") # 让用户选择要购买的花束和数量 choice = input("请输入要购买的花束编号(1-" + str(3) + "):") quantity = int(input("请输入要购买的数量:")) # 根据用户的选择计算总价 if choice == "1": total_price = bouquet1.price * quantity elif choice == "2": total_price = bouquet2.price * quantity elif choice == "3": total_price = bouquet3.price * quantity else: print("输入无效!") return # 输出总价和谢谢信息 print("您选择了购买 " + str(quantity) + " 个 " + eval("bouquet" + choice).name) print("总价为:" + str(total_price) + "元") print("谢谢惠顾!") # 调用主程序 main() ``` 在上面的代码中,我们首先定义了一个 `Bouquet` 类来表示花束。然后在主程序中,我们创建了几个 `Bouquet` 实例来表示三种不同的花束,并将它们的信息打印出来供用户选择。 用户输入要购买的花束编号和数量后,我们根据用户的选择计算总价,并输出购买信息和总价。如果用户输入了无效的选择,则程序会提示输入无效并退出。 这只是一个简单的示例,实际情况可能更复杂,需要根据具体需求进行修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值