ZOJ 3058 The War(简单贪心)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4351


题目大意:有N个士兵,每个士兵所能拿动的武器为【minWi, maxWi】,为了能打胜战,要尽可能多的拿到武器。问你如何能拿到更多。

其实这题和那个活动时间安排极其相似。比较简单,排序就好了。

#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;

typedef struct str{
    int minx;
    int maxx;
}str;

str st[2510];
int N, M, W;
int A[40010];
bool B[40010];

bool cmp(str A, str B)
{
    if(A.maxx==B.maxx)
        return A.minx<B.minx;
    return A.maxx<B.maxx;
}

int main(void)
{
    int i,j;
    while(-1!=scanf("%d %d", &N, &M))
    {
        int cnt=0;
        for(i=0; i<N; ++i)
            scanf("%d %d", &st[i].minx, &st[i].maxx);
        for(i=0; i<M; ++i)
            scanf("%d", &A[i]);
        sort(st, st+N, cmp);
        sort(A, A+M);
        memset(B, false, sizeof(B));
        for(i=0; i<N; ++i)
        {
            for(j=0; j<M; ++j)
            {
                if(!B[j] &&A[j]>=st[i].minx && st[i].maxx>=A[j])
                    break;
            }
            if(j==M)
                continue;
            B[j]=true;
            ++cnt;
        }
         printf("%d\n", cnt);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值