I - Other Side

滴答滴答---题目链接 

Other Side

/problems/otherside/file/statement/en/img-0001.jpg

Indiana Dunes State Park. Image by pixabay.

John Doe wants to transport his possessions from one bank of Lake Michigan to the other. His possessions consist of WW wolves, SSsheep, and CC cabbages. The transportation will be carried out using a boat that can hold up to KK of these items at the same time. During each step, John can take some items from one bank and transfer them to the other bank. Unfortunately, when left unsupervised, wolves will eat sheep and sheep will eat cabbages (but wolves don’t eat cabbages). John doesn’t want to lose his possessions, so he has to devise a scheme such that this doesn’t happen. With John present, any combination of items is allowed (both on the bank and in the boat). This is also true during the loading process. Since John isn’t very good at solving problems like this, he asks you to help him.

Input

Input contains a single line with four integers: WW, SS, CC, KK. The input satisfies the following constraints:

0≤W,S,C,K≤106,0≤W,S,C,K≤106,

1≤max(W,S,C).1≤max(W,S,C).

Output

If it’s possible to perform the transportation without the loss of items, print YES, otherwise print NO.

Sample Input 1 Sample Output 1
1 1 1 1
YES
Sample Input 2 Sample Output 2
2 2 0 1
NO

 Submit Stats

Problem ID: otherside

CPU Time limit: 1 second

Memory limit: 1024 MB

Difficulty: 7.2

Download: 
Sample data files

Author(s): Volodymyr Lyubinets

Source: 2018 ACM-ICPC North Central North America Regional Contest

 
   
Sample Input 2 Sample Output 2
2 2 0 1
NO
  1. 题意就是给你w头狼和s头羊和c个胡萝卜,每次可以运k个东东过河,狼会吃羊,羊会吃胡萝卜,不过当他们在船上时是互不干预的,问你,怎么样才可以不受缺的运这些东东过河;
  2. 具体过程看下列代码分类讨论就可以明白
  3. #include <iostream>
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    using namespace std;
    int main()
    {
        int w,s,c,k;
        scanf("%d%d%d%d",&w,&s,&c,&k);
        if(w+c>k&&s>k)
        {
            printf("NO\n");
            return 0;
        }
        if(s<k)
        {
            printf("YES\n");
            return 0;
        }
        if(w+c<k)
        {
            printf("YES\n");
            return 0;
        }
        if(w+c==k&&s<=2*k)
        {
            printf("YES\n");
            return 0;
        }
        if(s==k&&(w+c)<=2*k)
        {
            printf("YES\n");
            return 0;
        }
        printf("NO\n");
        return 0;
    }

猜你喜欢

转载自blog.csdn.net/chen_zan_yu_/article/details/84038428