Other SideIndiana 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. InputInput 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). OutputIf it’s possible to perform the transportation without the loss of items, print YES, otherwise print NO.
Problem ID: otherside CPU Time limit: 1 second Memory limit: 1024 MB Difficulty: 7.2 Download: Author(s): Volodymyr Lyubinets Source: 2018 ACM-ICPC North Central North America Regional Contest |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Sample Input 2 | Sample Output 2 |
---|---|
|
|
- 题意就是给你w头狼和s头羊和c个胡萝卜,每次可以运k个东东过河,狼会吃羊,羊会吃胡萝卜,不过当他们在船上时是互不干预的,问你,怎么样才可以不受缺的运这些东东过河;
- 具体过程看下列代码分类讨论就可以明白
-
#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; }