日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

省选专练之神仙贪心IOI2013Robert

發布時間:2025/4/16 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 省选专练之神仙贪心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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。