Educational Codeforces Round 112 (Rated for Div. 2)-A. PizzaForces-题解

Posted Tisfy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 112 (Rated for Div. 2)-A. PizzaForces-题解相关的知识,希望对你有一定的参考价值。

Educational Codeforces Round 112 (Rated for Div. 2)-A. PizzaForces

传送门
Time Limit: 2 seconds
Memory Limit: 256 megabytes

Problem Description

PizzaForces is Petya’s favorite pizzeria. PizzaForces makes and sells pizzas of three sizes: small pizzas consist of 6 6 6 slices, medium ones consist of 8 8 8 slices, and large pizzas consist of 10 10 10 slices each. Baking them takes 15 15 15, 20 20 20 and 25 25 25 minutes, respectively.

Petya’s birthday is today, and n n n of his friends will come, so he decided to make an order from his favorite pizzeria. Petya wants to order so much pizza that each of his friends gets at least one slice of pizza. The cooking time of the order is the total baking time of all the pizzas in the order.

Your task is to determine the minimum number of minutes that is needed to make pizzas containing at least n n n slices in total. For example:

Input

The first line contains a single integer t t t ( 1 ≤ t ≤ 1 0 4 1 \\le t \\le 10^4 1t104) — the number of testcases.

Each testcase consists of a single line that contains a single integer n n n ( 1 ≤ n ≤ 1 0 16 1 \\le n \\le 10^{16} 1n1016) — the number of Petya’s friends.

Output

For each testcase, print one integer — the minimum number of minutes that is needed to bake pizzas containing at least n n n slices in total.

Sample Input

6
12
15
300
1
9999999999999999
3

Sample Onput

30
40
750
15
25000000000000000
15

题目大意

有3种披萨分别能切成 6 、 8 、 10 6、8、10 6810块,制作它们分别需要 15 、 20 、 25 15、20、25 152025分钟。

n n n个人,没人至少分得一块儿披萨,一次只能烤一种,问最少需要几分钟。

解题思路

不难发现不论披萨能切成几块,每块儿需要的平均时间都是相同的。 15 6 = 20 8 = 25 10 = 2.5 \\frac{15}{6}=\\frac{20}{8}=\\frac{25}{10}=2.5 615=820=1025=2.5。但是主要就是不能分开做披萨,现在问题转化为如何用 6 , 8 , 10 6,8,10 6,8,10累加出一个最小的比 n n n大的数。

首先 6 , 8 , 10 6,8,10 6,8,10都只能加出偶数出来。

因此如果是奇数 n n n的话就可以 n + 1 n+1 n+1变成偶数,不受影响。都变成偶数后,我们就可以进行约分。

6 , 8 , 10 , 偶 数 化 的 n 6,8,10,偶数化的n 6,8,10,n的最大公约数是 2 2 2,因此就都除以 2 2 2,变成 3 , 4 , 5 , ⌊ n + 1 2 ⌋ 3,4,5,\\lfloor\\frac{n+1}{2}\\rfloor 3,4,5,2n+1进行比较。

那么 3 , 4 , 5 3,4,5 3,4,5能组合出哪些数呢?

能组合出 3 ∼ + ∞ 3\\sim+\\infin 3+的所有整数。

二三得六,正好比五大一;那七就可以由三和四组成; ⋯   ⋯ \\cdots\\ \\cdots  

也就是说,只要 n n n比较大(已经偶数化,可认为没有奇数n),就能正好不多做。
一块儿需要 2.5 2.5 2.5分钟,因为 n n n除以了 2 2 2,所以现在的一个 n n n需要 5 5 5分钟,正好还把小数避开了

但是如果人数 n n n特别小的话至少也得做一块儿最小的(花 15 15 15分钟)


AC代码

#include <bits/stdc++.h>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << #x << " = " << x << endl
#define fi(i, l, r) for (int i = l; i < r; i++)
#define cd(a) scanf("%d", &a)
typedef long long ll;
int main()
{
    int N;
    cin>>N;
    while(N--)
    {
        ll n;
        cin>>n;
        n++; // 若是奇数+1偶数化
        n/=2; // 与2约分
        n*=5; // 一块儿5分钟
        printf("%lld\\n",max(n,15ll)); // 总时间至少15分钟
    }
    return 0;
}

简化C版本

#include<stdio.h>
#define max(a,b) (a)>(b)?(a):(b)
int main()
{
    int N;
    scanf("%d",&N);
    while(N--)
    {
        long long n;
        scanf("%lld",&n);
        printf("%lld\\n",max(15,(n+1)/2*5));
    }
    return 0;
}

简化Python版本

N=int(input())
for _ in range(N):
    print(max(15,(int(input())+1)//2*5))

原创不易,转载请附上原文链接哦~
Tisfy:https://letmefly.blog.csdn.net/article/details/119271272

以上是关于Educational Codeforces Round 112 (Rated for Div. 2)-A. PizzaForces-题解的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 7 A

Educational Codeforces Round 7

Educational Codeforces Round 90

Educational Codeforces Round 33

Codeforces Educational Codeforces Round 54 题解

Educational Codeforces Round 27