本文已参与「新人创作礼」活动,一起开启掘金创作之路。
@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 slices, medium ones consist of slices, and large pizzas consist of slices each. Baking them takes , and minutes, respectively.
Petya's birthday is today, and 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 slices in total. For example:
Input
The first line contains a single integer () — the number of testcases.
Each testcase consists of a single line that contains a single integer () — 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 slices in total.
Sample Input
6
12
15
300
1
9999999999999999
3
Sample Onput
30
40
750
15
25000000000000000
15
题目大意
有3种披萨分别能切成块,制作它们分别需要分钟。
有个人,没人至少分得一块儿披萨,一次只能烤一种,问最少需要几分钟。
解题思路
不难发现不论披萨能切成几块,每块儿需要的平均时间都是相同的。。但是主要就是不能分开做披萨,现在问题转化为如何用累加出一个最小的比大的数。
首先都只能加出偶数出来。
因此如果是奇数的话就可以变成偶数,不受影响。都变成偶数后,我们就可以进行约分。
的最大公约数是,因此就都除以,变成进行比较。
那么能组合出哪些数呢?
能组合出的所有整数。
二三得六,正好比五大一;那七就可以由三和四组成;
也就是说,只要比较大(已经偶数化,可认为没有奇数n),就能正好不多做。 一块儿需要分钟,因为除以了,所以现在的一个需要分钟,正好还把小数避开了。
但是如果人数特别小的话至少也得做一块儿最小的(花分钟)
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…