-
E - Cats and Fish
- HihoCoder - 1631
- 题意:给定m条鱼,n只猫每只猫吃一条鱼的时间给定,然后给一个时间x问x时间后吃完了多少鱼还有多少鱼正在吃
- 思路:吃鱼一个循环过程但是有先后,所以根据优先级大小重构一下,按照优先队列去模拟这个过程即可,按照鱼的数量--进行队列元素循环更新,但是当队首元素的时间都超过x时就需要break
-
#include <iostream> #include <queue> #include <stdio.h> using namespace std; struct node { int v,w; bool operator<(const node&b)const { if(w==b.w)return v>b.v; return w>b.w; } } temp; int n,m,x,c,ans; int main() { while(~scanf("%d%d%d",&m,&n,&x)) { ans=0; priority_queue<node>q; for(int i=1; i<=n; i++) { scanf("%d",&c); q.push(node{c,0}); } while(m--) { if(q.top().w>=x)break; temp=q.top(); q.pop(); temp.w+=temp.v; q.push(temp); } while(!q.empty()) { temp=q.top(); q.pop(); if(temp.w-x>0&&temp.w-x<temp.v) ans++; } printf("%d %d\n",m+1,ans); } return 0; }
E - Cats and Fish HihoCoder - 1631 -模拟+priority-queue
猜你喜欢
转载自blog.csdn.net/BePosit/article/details/83819859
今日推荐
周排行