题意
链接: link.
你要烤n块披萨
一整块的披萨有3种规模
6块的需要15min
8块的需要20min
10块的需要25min
问你需要最少时间烤完
思路
首先
15/6=2.5
20/8=2.5
25/10=2.5
所以性价比都一样
那么8和10存在的意义是什么
假设计划全烤6块的,最后可能会剩下不够6块的,
可能是0到5,再烤一份那就需要15min
如果你把计划中最后一整块换一种规模,每多两块披萨你上升一种规模,这样浪费的最少,时间自然最小,噢原来8和10的存在是为了加钟的
代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2E5 + 10;
int arr[N];
int main()
{
int t;
cin >> t;
while (t--)
{
ll now;
cin >> now;
ll res = 0;
if (now <= 6)
{
res = 15;
}
else
{
res = now / 6 * 15;
now %= 6;
if (now == 0)
{
res += 0;
}
else if (now <= 2)
{
res += 5;
}
else if (now <= 4)
{
res += 10;
}
else
{
res += 15;
}
}
cout << res << endl;
}
// system("pause");
return 0;
}
代码虽然不简洁,但是好想,顺手就是最快的