题目描述:
有一个环形的市场,总共有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;
}