题解 | 买橘子

买橘子

https://www.nowcoder.com/practice/73e0552b78474a9086781e47f4e01d73

#include<bits/stdc++.h>
using namespace std;

using ll=long long;
using ull=unsigned long long;
using i128=__int128_t;
using u128=__uint128_t;
using ld=long double;

void solve()
{
	int n,MIN=-1;
	cin >> n;
	if(n<6)//小于6绝对不行
	{
		cout << MIN;
		return;
	}
	for(int i=0;;i++)//暴力找方案
	{
		int temp=i*8;
		if(n-temp<0) break;
		if((n-temp)%6==0) MIN=i+(n-temp)/6;
	}
	cout << MIN;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin >> t;
	
	while(t--)
	{
		solve();
	}
	return 0;
}

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务