我感觉快要成为每日水题了。。。。。。。
题目描述
小易去附近的商店买苹果,奸诈的商贩使用了捆绑交易,只提供6个每袋和8个每袋的包装(包装不可拆分)。 可是小易现在只想购买恰好n个苹果,小易想购买尽量少的袋数方便携带。如果不能购买恰好n个苹果,小易将不会购买。
输入描述:
输入一个整数n,表示小易想购买n(1 ≤ n ≤ 100)个苹果
输出描述:
输出一个整数表示最少需要购买的袋数,如果不能买恰好n个苹果则输出-1
#include<bits/stdc++.h>
using namespace std;
int main()
{
int count,temp=9999;
cin>>count;
for(int i=0;i<=(count/8);i++)
{
for(int j=0;j<=(count/6);j++)
{
if(i*8+j*6==count)
temp=min(temp,i+j);
}
}
if(temp!=9999)
cout<<temp;
else
cout<<"-1"<<endl;
return 0;
}