hdu 4864 2014STD D题

1、要能够分析出贪心的理由

2、在lv里面进行lower_bound : 因为对于task的time本来就已经是从大到小排好序的,对于task里的每个time我们应该从最小的level开始放,

      因为可能在task后面有比较大的lv;

3、lower_bound的用法

4、二分的写法

5、比较函数cmp


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define clr(x) memset(x,0,sizeof(x))
#define fp1 freopen("in.txt","r",stdin)
#define fp2 freopen("out.txt","w",stdout)
#define pb push_back

#define INF 0x3c3c3c3c
typedef __int64 LL;

const int maxn = 1e5+100;

typedef struct nn{
    LL time, lv;
}nn;
nn task[maxn], mac[maxn];
int N, M;
multiset<int> ss[150];
bool cmp(nn a, nn b){
    if(a.time>b.time) return true;
    else {
            if(a.time==b.time)  return a.lv > b.lv;
            else return false;
    }
    return false;
}
int main()
{
    //fp1;
    while(scanf("%d %d", &N, &M) == 2){
        for(int i = 0;i < 150;i++) ss[i].clear();
        for(int i = 1;i <= N;i++){
            scanf("%I64d %I64d", &mac[i].time, &mac[i].lv);
            ss[mac[i].lv].insert(mac[i].time);
        }

        for(int i = 1;i <= M;i++){
            scanf("%I64d %I64d", &task[i].time, &task[i].lv);
        }

        sort(task+1, task+1+M, cmp);

        LL count = 0, sum = 0;
        for(int i = 1;i <= M;i++){
            for(int j = task[i].lv;j < 150;j++){
                if(ss[j].size() == 0) continue;
                if(ss[j].lower_bound(task[i].time) == ss[j].end()) {
                    continue;
                }
                else{
                    count ++;
                    multiset<int>::iterator it = ss[j].lower_bound(task[i].time);
                    sum += (task[i].time*500 + task[i].lv*2);
                    ss[j].erase(it);
                    break;
                }
            }
        }
        printf("%I64d %I64d\n", count, sum);
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值