省选专练之神仙贪心IOI2013Robert
【問題描述】 小沐把玩具扔在地板上,亂七八糟。慶幸的是,有一種特殊的機器人可以收拾玩具。不過他需要 確定哪個機器人去揀哪個玩具。 一共有 T 個玩具,整數 w[i]表示這個玩具的重量,整數 s[i]表示這個玩具的體積。機器人有 兩種,分別是:弱機器人和小機器人。
◆有 A 個弱機器人。每個弱機器人有一個重量限制 X[i],它只能拿起重量嚴格小于 x[i]的玩 具,與玩具的體積大小沒有關系。
◆有 B 個小機器人。每個小機器人有一個體積限制 Y[i],它只能拿起體積嚴格小于 Y[i]的玩 具,與玩具的重量大小沒有關系。 每個
機器人用 1 分鐘將一個玩具拿走放好。不同的機器人可以同時拿走并放好不同的玩具。 你的任務是確定機器人是否可以將所有玩具都收拾好,如果是,那么最少用多少時間可以收拾好。
Marita's little brother has left toys all over the living room floor! Fortunately, Marita has developed special robots to clean up the toys. She needs your help to determine which robots should pick up which toys. There are T toys, each with an integer weight W[i] and an integer size S[i] . Robots come in two kinds: weak and small.
There are A weak robots. Each weak robot has a weight limit X[i] , and can carry any toy of weight strictly less than X[i] . The size of the toy does not matter.
There are B small robots. Each small robot has a size limit Y[i] , and can carry any toy of size strictly less than Y[i] . The weight of the toy does not matter.
Each of Marita's robots takes one minute to put each toy away. Different robots can put away different toys at the same time. Your task is to determine whether Marita's robots can put all the toys away, and if so, the shortest time in which they can do this.
這居然不是IOI的簽到題(Day2-T5)
神仙貪心。
明顯發現答案成一個單調的情況
二分答案
如何貪心:先對詢問以重量關鍵字排序
對weak再按照盡可能取體積大的原則取走
對于剩下small的按照盡可能取體積大的原則取走
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<queue> using namespace std; typedef int INT; #define int long long const int N=1e6+10; struct Node{int x,y; }S[N],tmp[N]; int X[N]; int Y[N]; int T,A,B; priority_queue<Node> Q; bool cmp(Node A,Node B){return A.x<B.x; } bool cmp2(int A,int B){return A>B; } bool operator < (Node A,Node B){return A.y<B.y; } bool check(int sum){while(!Q.empty())Q.pop();int now=1;for(int i=1;i<=A;++i){while(S[now].x<X[i]&&now<=T)Q.push(S[now]),++now;for(int j=1;!Q.empty()&&j<=sum;++j)Q.pop();}while(now<=T)Q.push(S[now]),++now;for(int i=1;i<=B;i++){for(int j=1;j<=sum&&!Q.empty()&&Q.top().y<Y[i];++j)Q.pop();}if(!Q.empty())return 0;return 1; } INT main(){ // freopen("test.in","r",stdin);scanf("%lld%lld%lld",&A,&B,&T);for(int i=1;i<=A;++i)scanf("%lld",&X[i]);sort(X+1,X+1+A);for(int i=1;i<=B;++i)scanf("%lld",&Y[i]);sort(Y+1,Y+1+B,cmp2);for(int i=1;i<=T;++i){scanf("%lld%lld",&S[i].x,&S[i].y);}sort(S+1,S+1+T,cmp);int l=1;int r=T+1;int ans=-1;while(l<=r){int mid=(l+r)/2;if(check(mid)){ans=mid;r=mid-1;}else l=mid+1;}cout<<ans; }?
轉載于:https://www.cnblogs.com/Leo-JAM/p/10079128.html
總結
以上是生活随笔為你收集整理的省选专练之神仙贪心IOI2013Robert的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c语言实践 1/1+1/2+1/3+1/
- 下一篇: ubuntu下 将证书导入java的ca