首页 > 试题广场 >

牛牛吃雪糕

[编程题]牛牛吃雪糕
  • 热度指数:928 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
最近天气太热了,牛牛每天都要吃雪糕。雪糕有一盒一份、一盒两份、一盒三份这三种包装,牛牛一天可以吃多盒雪糕,但是只能吃六份,吃多了就会肚子疼,吃少了就会中暑。而且贪吃的牛牛一旦打开一盒雪糕,就一定会把它吃完。请问牛牛能健康地度过这段高温期么?

输入描述:
每个输入包含多个测试用例。
输入的第一行包括一个正整数,表示数据组数T(1<=T<=100)。
接下来N行,每行包含四个正整数,表示高温期持续的天数N(1<=N<=10000),一盒一份包装的雪糕数量A(1<=A<=100000),一盒两份包装的雪糕数量B(1<=B<=100000),一盒三份包装的雪糕数量C(1<=A<=100000)。


输出描述:
对于每个用例,在单独的一行中输出结果。如果牛牛可以健康地度过高温期则输出"Yes",否则输出"No"。
示例1

输入

4 
1 1 1 1 
2 0 0 4 
3 0 2 5 
4 24 0 0

输出

Yes 
Yes 
No 
Yes
#include <iostream>
#include <vector>
using namespace std;
bool fun(int n,int a,int b,int c){
    if(a + 2 * b + 3 * c < n)
        return false;
    n -= c / 2;
    n -= b / 3;
    b %= 3;
    c %= 2;
    if(n <= 0)
        return true;
    if(n * 6 - b * 2 - c * 3 > 0 && n * 6 - b * 2 - c * 3 <= a)
        return true;
    else
        return false;
}
int main(){
    int t;
    cin >> t;
    for(int i = 0;i < t;i++){
        int n,a,b,c;
        cin >> n >> a >> b >> c;
        bool flag = fun(n,a,b,c);
        if(flag)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}
</vector></iostream>

发表于 2019-07-23 22:17:24 回复(0)
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int T,N,A,B,C;
cin>>T;
for(int i=0;i<T;i++)
{
cin>>N>>A>>B>>C;
N=N-B/3-C/2;
B%=3;
C%=2;
if(N<=0)cout<<"Yes"<<endl;
else if((A+B*2+3*C<6*N)||((A+B*2+3*C>=6*N)&&(A==0)))cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}
return 0;
}

编辑于 2018-05-28 20:42:55 回复(0)
python 处理这道题的输入 一直出现问题
发表于 2018-05-25 15:21:23 回复(0)

多一个的情况下特判就可以了

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        while (T-- != 0) {
            int s = scanner.nextInt();
            int one = scanner.nextInt();
            int two = scanner.nextInt();
            int three = scanner.nextInt();
            boolean res = getResult(s, one, two, three);
            System.out.println(res ? "Yes" : "No");
        }
    }

    private static boolean getResult(int s, int one, int two, int three) {
        int sum = one + two * 2 + three * 3;
        s *= 6;
        if (sum < s) return false;
        if (sum - s == 1) {
            return one >= 1;
        }
        return true;
    }
}
编辑于 2019-02-21 17:56:38 回复(0)
#include<bits/stdc++.h>
using namespace std;

bool calc(int N, int A, int B, int C) {
    N -= C / 2 + B / 3;
    C %= 2, B %= 3;
    if (N <= 0) return true;
    if (A <= 0) return false;
    if (C > 0 && B > 0) N--, A--, B--, C--;
    // 此刻,B、C 至少有一个为 0
    if (C > 0 && A >= 3) N--, A -= 3;
    if (B > 0 && A >= 6 - B * 2) N--, A -= 6 - B * 2;
    return N <= A / 6;
}

int main() {
    int T;
    cin >> T;
    while (T--) {
        int N, A, B, C;
        cin >> N >> A >> B >> C;
        cout << (calc(N, A, B, C) ? "Yes" : "No") << endl;
    }
    return 0;
}


发表于 2021-08-10 22:48:05 回复(0)
#include <stdio.h>
int main() {
    int a;
    scanf("%d",&a);
    int b,c,d,e;
    for(int i=0;i<a;i++)
    {
        scanf("%d %d %d %d",&b, &c, &d, &e);
        
        if((c+2*d+3*e)>=b*6)
        {
            if((c+2*d+3*e)==(b*6+1))
            {
                bool a1=(c==0);
                if(a1)
                    printf("No\n");
                else
                    printf("Yes\n");
            }
            else
                printf("Yes\n");
        }
        else
            printf("No\n");
    }

    return 0;
}
发表于 2021-07-27 22:31:54 回复(0)
下次遇到这类题,将1留着补位,将2、3先用来单独凑。凑不好的,用1来补

import java.util.Scanner;
  
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        while (T-- != 0) {
            int s = scanner.nextInt();
            int one = scanner.nextInt();
            int two = scanner.nextInt();
            int three = scanner.nextInt();
            System.out.println(f(one ,two, three, s ));
        }
    }
     
        public static String f(int x,int y,int z,int n){
            if(x+2*y+z*3<6*n)return "No";
            //n-=x/6;
            n-=y/3;
            n-=z/2;
            if(n<=0)return "Yes";//剪完之后看n是否已经结束了,没结束就继续楼
            //x%=6;
            y%=3;
            z%=2;
             //就是缺的,如果缺的小于x就好了
            
            if(n*6 -y*2-z*3<=x && n*6 -y*2-z*3>=0)
                return "Yes";
            else
                return "No";
    }
}

编辑于 2019-03-21 22:23:54 回复(0)
# 不知道为何通过率为20.00%
import sys
s=sys.stdin.readlines()
s=s[1:]
for x in s:
    ans=0
    x=x.strip()
    l=x.split()
    l=list(map(int,l))
    day=l[0]
    one=l[1]
    two=l[2]
    three=l[3]
    ans=int(three/2)
    ans+=int(two/3)
    ans += int(one / 6)
    three_left=three%2
    two_left=two%3
    one_left=one%6
    if three_left==1:
        if (two_left)&(one_left):
            two_left-=1
            one_left-=1
            three_left=0
            ans+=1
        elif(not two_left)&(one_left>=3)&(three_left):
            one_left -= 3
            ans += 1
    if (2*two_left+one_left)>=6:
        ans+=1
    if ans>=day:
        print('Yes')
    else:
        print('No')


编辑于 2019-02-24 16:54:08 回复(0)

2018年校招全国统一模拟笔试(五月场)编程题集合 - 题解

https://blog.csdn.net/FlushHip/article/details/80446002

发表于 2018-05-25 02:57:24 回复(0)
// [编程题]牛牛吃雪糕.cpp : 定义控制台应用程序的入口点。
//
#include 
#include 
using namespace std;
int main()
{
    int t;
    cin >> t;
    while (t--) {
        int n, a, b, c;
        cin >> n >> a >> b >> c;
        int res = c / 2;
        if (c % 2 == 1) {
            if (a > 0 && b > 0) {
                res++;
                a--;
                b--;
                c = 0;
            }
            else if (a >= 3) {

                ++res;
                a -= 3;
                c = 0;
            }
        }
        res += b / 3;
        b %= 3;
        res  += a / 6;
        a %= 6;
        if (2 * b + a >= 6)
            ++res;
        if (res >= n)
            cout << "Yes" << endl;
        else 
            cout<<"No"<<endl;
    }
    return 0;
}
编辑于 2018-05-25 13:41:58 回复(2)

热门推荐

通过挑战的用户