题目描述:
一农夫带着m只羊,n只狼过河,农夫有一条可载x只狼/羊的船;农夫在时或者羊的数量大于狼时,狼不会攻击羊;农夫在不损失羊的情况下,运输几次可以完成运输?(返程不计入次数)
输入描述:
输入参数为 m, n , x;
m 为羊的数量、n为狼的数量、x为可载狼和羊的数量
输出描述:
返回运输次数即可
补充说明:
如果无法完成运输返回0;
收起
示例1
输入:
5 3 3
输出:
3
说明:
详解:
第一次:2只狼
第二次:三只羊
第三次:2只羊,1只狼
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
int x = sc.nextInt();
int counts = 1;
if(x>m){
counts++;
if(n>m&&n<(2*(x-1))){
counts++;
}