codeforces 1073 D

题目描述:

有一个环形的市场,总共有n个摊位.
每个摊位的商品价格为a[i].
(n号摊位和1号摊位相邻).
现在小x从1号摊位开始,进行如下的购买策略:
1.如果他有足够的钱能够在第i号摊位购买它的商品,那么他就会买下该商品.
2.这之后,他会走到下一个摊位,如果当前摊位为n号,那么下一个摊位为1号摊位.
问如果小x初始的时候有T元钱的话,可以购买多少个商品.

Example

Input

3 38
5 2 5

Output

10

这个题不多讲,就是我当时写的时候懵逼了,没想到这样算,当个错题放这里吧,时时刻刻提醒自己

认真分析问题

思路也很简单,暴力循环,没得到一个值,顺便记录本次的消费,计算过后,看看当前剩余的钱中有多少个这样的cost,全部剪掉,把res更新成为本次购买的商品的对应的倍数即可,比赛时,我竟然把它想成了贪心,傻了傻了

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

typedef long long ll;
ll n, t;
const ll maxn = 2 * 1e5 + 10;
ll arr[maxn];
#define endl "\n"
int main()
{
#ifdef endl
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);
#endif
	cin >> n >> t;
	for(int i = 1; i <= n; i++)cin >> arr[i];
	ll mn = *min_element(arr + 1, arr + 1 + n);
	ll res = 0;
	while(t >= mn){
		ll cnt, cost;
		cnt = 0;
		cost = 0;
		ll tt = t;
		for(int i = 1; i <= n; i++){
			if(tt >= arr[i]){
				tt -= arr[i];
				cnt++;
				cost += arr[i];
			}
		}
		ll temp = t / cost;
		t -= cost * temp;
		res += cnt * temp;
	}
	cout << res << endl;
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值