码迷,mamicode.com
首页 > 其他好文 > 详细

POJ3614 Sunscreen 贪心

时间:2018-07-15 19:28:34      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:include   std   贪心   bsp   ***   gre   div   class   col   

先按照minSPF排序,然后每次选择最大可以选的就可以了。

注意反向map的lower还是upper

技术分享图片
 1 /* ***********************************************
 2 Author        :BPM136
 3 Created Time  :2018/7/15 17:05:21
 4 File Name     :3614.cpp
 5 ************************************************ */
 6 
 7 #include<iostream>
 8 #include<cstdio>
 9 #include<algorithm>
10 #include<cstdlib>
11 #include<cmath>
12 #include<cstring>
13 #include<vector>
14 #include<map>
15 using namespace std;
16 
17 typedef long long ll;
18 typedef map<int,int, greater<int > > MIIG;
19 
20 const int N = 100005;
21 
22 int n,m;
23 
24 struct cow {
25     int mn,mx;
26 }a[N];
27 bool cmp_a(cow a,cow b) {
28     if(a.mn==b.mn) return a.mx<b.mx;
29     return a.mn>b.mn;
30 }
31 
32 int main() {
33     MIIG M;
34     M.clear();
35 
36     scanf("%d%d",&n,&m);
37     for(int i=1;i<=n;i++) scanf("%d%d",&a[i].mn,&a[i].mx);
38     for(int i=1;i<=m;i++) {
39         int v,nm;
40         scanf("%d%d",&v,&nm);
41         M[v]+=nm;
42     }
43     sort(a+1,a+n+1,cmp_a);
44     int ans=0;
45     for(int i=1;i<=n;i++) {
46         MIIG::iterator t=M.lower_bound(a[i].mx);
47         if(t==M.end() || t->first<a[i].mn) continue;
48         t->second--;
49         ans++;
50         if(t->second==0) M.erase(t);
51     }
52     cout<<ans<<endl;
53     return 0;
54 }
View Code

 

POJ3614 Sunscreen 贪心

标签:include   std   贪心   bsp   ***   gre   div   class   col   

原文地址:https://www.cnblogs.com/MyGirlfriends/p/9314270.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!