2021春季美团第九次笔试第一题
题目:
小团的蛋糕铺长期霸占着美团APP中“蛋糕奶茶”栏目的首位,因此总会吸引各路食客前来探店。
小团一天最多可以烤n个蛋糕,每个蛋糕有一个正整数的重量。
早上,糕点铺已经做好了m个蛋糕。
现在,有一个顾客要来买两个蛋糕,他希望买这一天糕点铺烤好的最重的和最轻的蛋糕,并且希望这两个蛋糕的重量恰好为a和b。剩余的n-m个蛋糕可以现烤,请问小团能否满足他的要求?
代码:
1 import java.io.*; 2 import java.io.IOException; 3 import java.util.TreeSet; 4 /** 5 * @author zcy 6 * @date 2021年04月03日 13:09 7 */ 8 public class Main { 9 public static void main(String[] args) throws IOException{ 10 BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); 11 String s; 12 while((s=reader.readLine())!=null) { 13 String[] str0 = s.split(" "); 14 int n = Integer.parseInt(str0[0]); 15 int m = Integer.parseInt(str0[1]); 16 int a = Integer.parseInt(str0[2]); 17 int b = Integer.parseInt(str0[3]); 18 int t = Math.min(a, b); 19 b = Math.max(a, b); 20 a=t; 21 String[] str1 = reader.readLine().split(" "); 22 TreeSet<Integer> set=new TreeSet<>(); 23 for(String str2:str1){ 24 set.add(Integer.parseInt(str2)); 25 } 26 int current_a=set.first(); 27 int current_b=set.last(); 28 if (current_a <a || current_b > b) { 29 System.out.println("NO"); 30 }else{ 31 int count = 0; 32 if (current_a == a) { 33 count++; 34 } 35 if (current_b == b) { 36 count++; 37 } 38 if ((count == 2) || (count == 1 && n - m >= 1) || (count == 0 && n - m >= 2)) { 39 System.out.println("YES"); 40 } else { 41 System.out.println("NO"); 42 } 43 } 44 45 } 46 } 47 48 }
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术