美团8.27笔试

有大佬做出来喂猫那道题吗?求思路#美团##美团笔试##提前批#
全部评论
每次遇到玩具,就把玩具的时间加入小根堆,遇到猫就从小根堆里拿一个时间,如果时间比直接摸的时间小就用堆顶时间,否则就直接摸。
3 回复 分享
发布于 2022-08-27 19:12 重庆
最小堆就行
1 回复 分享
发布于 2022-08-27 20:03 陕西
import java.util.*; class Main {     public static void main(String[] args) {         Scanner sc = new Scanner(System.in);         int n = sc.nextInt();         int k = sc.nextInt();         int T = sc.nextInt();         int[] toy=new int[k];         for (int i = 0; i < k; i++) {             toy[i]= sc.nextInt();         }         int res=0;         PriorityQueue<Integer> pq=new PriorityQueue<>();         for (int i = 0; i < n; i++) {             int x=sc.nextInt();             if(pq.size()==0&&x==0){                 res+=T;             }else if(x>0&&x-1<k&&toy[x-1]<T){//key point                 pq.add(toy[x-1]);             }else if(x==0){                 res+=pq.poll();             }         }         System.out.println(res);     } }
1 回复 分享
发布于 2022-08-27 19:21 甘肃
优先队列
1 回复 分享
发布于 2022-08-27 19:19 天津
直接模拟过程即可
1 回复 分享
发布于 2022-08-27 19:06 江苏

相关推荐

09-13 10:30
门头沟学院 Java
点赞 评论 收藏
分享
牛客48826091...:哥们胸肌挺好看
点赞 评论 收藏
分享
09-01 11:31
门头沟学院 Java
buul:七牛云的吧,感觉想法是好的,但是大家没那么多时间弄他这个啊。。。不知道的还以为他是顶尖大厂呢还搞比赛抢hc,只能说应试者的痛苦考察方是无法理解的,他们只会想一出是一出
点赞 评论 收藏
分享
评论
点赞
3
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务