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

54 阅读2分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

@TOC

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 66 slices, medium ones consist of 88 slices, and large pizzas consist of 1010 slices each. Baking them takes 1515, 2020 and 2525 minutes, respectively.

Petya's birthday is today, and nn 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 nn slices in total. For example:

Input

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

Each testcase consists of a single line that contains a single integer nn (1n10161 \le n \le 10^{16}) — 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 nn slices in total.

Sample Input

6
12
15
300
1
9999999999999999
3

Sample Onput

30
40
750
15
25000000000000000
15

题目大意

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

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

解题思路

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

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

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

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

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

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

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

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

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


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))

同步发文于CSDN,原创不易,转载请附上原文链接哦~
Tisfy:letmefly.blog.csdn.net/article/det…