题目
高温阶段,牛牛必须一天吃6份冰激凌,吃多了吃坏肚子,吃少了会中暑。有三种冰激凌分别是一盒一份,一盒两份,一盒三份。牛牛只要拆开一盒就会没有节制的吃完一整盒。根据输入判断牛牛是否能健康的度过高温阶段。
输入:
2 //输入的数组个数
1 1 1 1 //天数 第一种冰激凌的份数,第二种份数,第三种份数
3 0 2 5
输出:
Yes
No
import java.util.Scanner;
import java.util.ArrayList;
public class IceCream {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();//数组的个数
ArrayList<String> arr = new ArrayList<>();
for (int i = 0;i<n;i++){
int d = sc.nextInt();//高温天数
int a = sc.nextInt();//一盒一份冰激凌的份数
int b = sc.nextInt();//一盒两份冰激凌的份数
int c = sc.nextInt();//一盒三份冰激凌的份数
if(6*d>(a+2*b+3*c)){
//System.out.println("No");
arr.add("No");
}
else if((3*c)%2!=0&&a==0){
//System.out.println("No");
arr.add("No");
}else{
//System.out.println("Yes");
arr.add("Yes");
}
}
for(String q:arr){
System.out.println(q);
}
}
}
题目
牛牛能活几天。啊哈哈。牛牛每天必须要吃一个水果和交房租才能活。牛牛自身就有一些水果和一些钱,钱也可以买水果,问牛牛最多能活多久??
(其实我想说如果可以卖水果更好玩)
输入
3 5 100 10 //房租/天; 已有的水果数; 钱; 买每个水果的价格
输出
牛牛最多活得天数
import java.util.Scanner;
/*最优解就是买合适的水果数量,使得房租有钱付的前提能生活下去。
简单说,最完美的结局是最后吃的没有住的也付不起房租就好了。
同时要考虑一种情况,就是吃能撑的天数远远大于所有钱来付房租能住的天数*/
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();//房租/天
int f = sc.nextInt();//已有的水果个数
int m = sc.nextInt();//拥有的金钱
int p = sc.nextInt();//每个水果的价格
int num = 0;//假定独立生活最长时间时必须买的水果数量
int temp1 = ((m-num*p)/x);//买过num个水果后可以住多少天
int temp2 = f+num;//水果能撑多少天
if(temp1 < temp2){
System.out.println(temp1);
}else{
while(temp1>=temp2){
++num;
temp1 = ((m-num*p)/x);
temp2 = f+num;
}
System.out.println(temp2-1);
}
}
}