每个输入包含多个测试用例。
输入的第一行包括一个正整数,表示数据组数T(1<=T<=100)。
接下来N行,每行包含四个正整数,表示高温期持续的天数N(1<=N<=10000),一盒一份包装的雪糕数量A(1<=A<=100000),一盒两份包装的雪糕数量B(1<=B<=100000),一盒三份包装的雪糕数量C(1<=A<=100000)。
对于每个用例,在单独的一行中输出结果。如果牛牛可以健康地度过高温期则输出"Yes",否则输出"No"。
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>
#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;}
多一个的情况下特判就可以了
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;
}
}
#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; }
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"; } }
// [编程题]牛牛吃雪糕.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;
}