Codeforces Round#524 A-Petya and Origami (签到题)

版权声明:欢迎评论与转载,转载时请注明出处! https://blog.csdn.net/wjl_zyl_1314/article/details/84504492

原题链接:
http://codeforces.com/contest/1080/problem/A
A. Petya and Origami
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Petya is having a party soon, and he has decided to invite his n friends.

He wants to make invitations in the form of origami. For each invitation, he needs two red sheets, five green sheets, and eight blue sheets. The store sells an infinite number of notebooks of each color, but each notebook consists of only one color with k sheets. That is, each notebook contains k sheets of either red, green, or blue.

Find the minimum number of notebooks that Petya needs to buy to invite all n of his friends.

Input
The first line contains two integers n and k (1≤n,k≤108) — the number of Petya’s friends and the number of sheets in each notebook respectively.

Output
Print one number — the minimum number of notebooks that Petya needs to buy.

Examples
input
3 5
output
10
input
15 6
output
38
Note
In the first example, we need 2 red notebooks, 3 green notebooks, and 5 blue notebooks.

In the second example, we need 5 red notebooks, 13 green notebooks, and 20 blue notebooks.
题意:
有n个人,每个人都需要2个红色的表,5个绿色的表,8个蓝色的表,现在去买表,每一套表都是由同一种颜色的k个表组成的,问要给所有人需要的表,最少需要买几套?
题解:
签到题,乘法得出每种颜色所需要的个数,除以k向上取整即可。
附上AC代码:

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    int n,k;
    int red,green,blue;
    int cnt=0;
    scanf("%d%d",&n,&k);
    red=2*n;
    green=5*n;
    blue=8*n;
    cnt+=red/k;
    if(red%k!=0)
        cnt++;
    cnt+=green/k;
    if(green%k!=0)
        cnt++;
    cnt+=blue/k;
    if(blue%k!=0)
        cnt++;
    printf("%d",cnt);
    return 0;
}

欢迎评论!

猜你喜欢

转载自blog.csdn.net/wjl_zyl_1314/article/details/84504492