水果摊小买卖

水果摊小买卖

**题目描述:**小王手里有点闲钱,想着做点卖水果的小买卖。给出两个数组 m、n,用 m[i]代表第 i 个水果的成本价,n[i]代表第 i 水果能卖出的价钱,假如现在有本钱 k,试问最后最多能赚多少钱?
说明:
1 每种水果只需买一次,只能卖一次
2 数组 m、n 大小不超过 50
3 数组元素为正整数,不超过 1000
输入描述:
1 数组 m、n
2 本钱 k
备注:
1 首行输入逗号分隔的数组 m 的元素值
2 第二行输入逗号分隔的数组 n 的元素值
3 第三行输入本钱
输出描述:
最多能赚取多少钱。
示例 1
输入
4, 2, 6, 4
5, 3, 8, 7
15
输出
22
解题思路:
最直接的想法就是贪婪算法,每次选择当前成本能够购买的、利润最大的水果,然后卖出去,继续选择更新之后成本能够购买的、利润最大的水果,然后卖出去。

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<sstream>
using namespace std;

typedef struct ProductInfo{
	int cost;
	int profit;
	int isbuy=0;
}ProductInfo;

vector<int>StringToVector(const string& str){
	stringstream sstream(str);
	string token="";
	vector<int> vec_str;
	vec_str.clear();
	while(getline(sstream,token,',')){
		int num=0;
		for(int i=0;i<token.size();i++){
			num=10*num+token[i]-'0';
		}
		vec_str.push_back(num);
	}
	return vec_str;
}
bool Compare(const ProductInfo& a,const ProductInfo& b){
	return a.profit>b.profit;
}
bool CheckInfo(vector<ProductInfo>& productinfos,int cost_k){
	bool flag=false;
	for(int i=0;i<productinfos.size();i++){
		if(productinfos[i].isbuy==1){
			continue;
		}
		if(productinfos[i].profit<0){
			continue;
		}
		if(productinfos[i].cost<cost_k){
			flag=true;
			break;
		}
	}
	return flag;
}
int main(){
	string m="";
	while(getline(cin,m)){
		if (m.empty()) {
			break;
		}
		string n="";
		getline(cin,n);
		int k;
		cin>>k;
		vector<int> vec_m=StringToVector(m);
		vector<int> vec_n=StringToVector(n);
		vector<ProductInfo> productinfos;
		productinfos.clear();
		for(int i=0;i<vec_m.size();i++){
			ProductInfo productinfo;
			productinfo.cost=vec_m[i];
			productinfo.profit=vec_n[i]-vec_m[i];
			if(productinfo.profit<=0){
				continue;
			}
			productinfo.isbuy=0;
			productinfos.push_back(productinfo);
		}
		sort(productinfos.begin(),productinfos.end(),Compare);
		int cost_k=k;
		while(CheckInfo(productinfos,cost_k)){
			for(int i=0;i<productinfos.size();i++){
				if(productinfos[i].cost>cost_k){
					continue;
				}
				if(productinfos[i].profit<=0){
					continue;
				}
				if(productinfos[i].isbuy==1){
					continue;
				}
				cost_k+=productinfos[i].profit;
				productinfos[i].isbuy=1;
			}
		}
		cout<<cost_k<<endl;
	}
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
非常感谢您的问题,我会尽力回答。根据您的要求,以下是一个简单的商业计划书,描述了一个买农民水果的APP的概念和商业模式。 1. 产品概述 我们的APP旨在为消费者和农民之间建立一个直接的联系,让消费者可以直接购买新鲜的水果直接从农民那里购买。这个APP将提供一个简单而直接的购买平台,从而帮助农民减少中间渠道和成本,同时也让消费者获得更好的价格和质量保证。 2. 商业模式 我们的商业模式将依赖于两种主要的收入来源:第一种是从农民那里收取一定比例的交易费用,这将是我们的主要收入来源;第二种是从广告和促销收取一定比例的费用,这将是我们的次要收入来源。 3. 目标市场 我们的目标市场是那些关心健康、喜欢新鲜、有意愿购买农民水果的消费者。我们将主要针对城市居民和中高收入人群,因为这些人群更有可能使用智能手机和在线购物平台。 4. 竞争分析 我们的主要竞争对手是其他在线购物平台和生鲜超市。我们将通过提供更好的价格、更好的质量保证和更直接的购买方式来区分自己。 5. 市场推广 我们将通过广告宣传、社交媒体和口碑营销来推广我们的APP。我们还将与农民和当地政府合作,以促进我们的品牌和市场知名度。 6. 经营管理 我们的团队将由技术人员、市场营销人员和客户服务人员组成。我们将积极寻求投资,以支持我们的扩张和技术开发。 7. 财务规划 我们的财务规划将依赖于用户数量和交易量。我们预计,我们的APP将在第二年实现盈利,并在未来几年内实现可持续的增长。 感谢您阅读我们的商业计划书,如果您有任何问题或建议,请随时联系我们。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值