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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

POJ3614Sunscreen(优先队列+贪心)

發布時間:2024/10/6 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ3614Sunscreen(优先队列+贪心) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Sunscreen

Time Limit:?1000MS?Memory Limit:?65536K
Total Submissions:?8435?Accepted:?2981

Description

To avoid unsightly burns while tanning, each of the?C?(1 ≤?C?≤ 2500) cows must cover her hide with sunscreen when they're at the beach. Cow?i?has a minimum and maximum?SPF?rating (1 ≤?minSPFi?≤ 1,000;?minSPFi?≤?maxSPFi?≤ 1,000) that will work. If the?SPF?rating is too low, the cow suffers sunburn; if the?SPF?rating is too high, the cow doesn't tan at all........

The cows have a picnic basket with?L?(1 ≤?L?≤ 2500) bottles of sunscreen lotion, each bottle?i?with an?SPF?rating?SPFi?(1 ≤?SPFi?≤ 1,000). Lotion bottle?i?can cover?coveri?cows with lotion. A cow may lotion from only one bottle.

What is the maximum number of cows that can protect themselves while tanning given the available lotions?

Input

* Line 1: Two space-separated integers:?C?and?L
* Lines 2..C+1: Line?i?describes cow?i's lotion requires with two integers:?minSPFi?and?maxSPFi?
* Lines?C+2..C+L+1: Line?i+C+1 describes a sunscreen lotion bottle?i?with space-separated integers:?SPFi?and?coveri

Output

A single line with an integer that is the maximum number of cows that can be protected while tanning

Sample Input

3 2 3 10 2 5 1 5 6 2 4 1

Sample Output

2

Source

USACO 2007 November Gold

題意:有C頭奶牛要去沐光浴,太陽光太強烈會曬壞皮膚,太弱又會沒效果。每頭牛都有一個太陽光適宜的范圍經行沐光浴,分別給出minspf_i和maxspf_i。 有L種防曬霜,每種防曬霜可以把所受陽光固定于一個值spf_i,每種有cover_i瓶。 問最多會有幾頭牛得到合適的光曬強度?

題解:

貪心策略,在滿足minspf的條件下,盡量將spf的防曬霜涂到maxspf小的奶牛身上,因為maxspf大的奶牛有更多的選擇。

這里就需要一個優先隊列來儲存滿足minspf的奶牛的maxspf的值。 具體解題步驟如下:

1.將奶牛按照minspf升序排列,將防曬霜按照spf升序排列。

2.枚舉防曬霜,將minspf<=spf的奶牛的maxspf存到優先隊列中,然后值小的先出隊列,

看是否滿足maxspf>=spf,更新記錄值。

#include<bits/stdc++.h> using namespace std; struct cow {int min_spf,max_spf; }; struct suns {int spf,num; }; vector<cow> c; vector<suns> s; int n,m; bool cmp1(cow a,cow b) {return a.min_spf<b.min_spf; } bool cmp2(suns a,suns b) {return a.spf<b.spf; } priority_queue<int,vector<int>,greater<int> >qua; int main() {cin>>n>>m;for(int i=0;i<n;i++){cow tmp;cin>>tmp.min_spf>>tmp.max_spf;c.push_back(tmp);}for(int i=0;i<m;i++){suns tmp;cin>>tmp.spf>>tmp.num;s.push_back(tmp);}sort(c.begin(),c.end(),cmp1);sort(s.begin(),s.end(),cmp2);int ans=0,cnt=0;for(int i=0;i<m;i++){while(cnt<n&&c[cnt].min_spf<=s[i].spf){qua.push(c[cnt].max_spf);cnt++;}while(s[i].num!=0&&!qua.empty()){int k=qua.top();qua.pop();if(k>=s[i].spf){ans++;s[i].num--;}}}cout<<ans<<endl; }

?

總結

以上是生活随笔為你收集整理的POJ3614Sunscreen(优先队列+贪心)的全部內容,希望文章能夠幫你解決所遇到的問題。

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