hdu2863 2010.3.6

hdu2863 2010.3.6

朴素的贪心。。比赛的时候居然没想到,不要被题目骗了,有些看起来是dp的题,其实是贪心

 

Top Shooter

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 162    Accepted Submission(s): 47

 

 

Problem Description

Since the Border War in 1962, Both Chinaand India abide by theprinciple of no-expansion of military power, but India's recent actions areobviously going against this principle. Indian Prime Minister Singh delivered aspeech in Congress, said that "regardless of face of China or other countries, India will, byall means to ensure the territorial integrity, national unity andsecurity."

At the same time, India increasesmore than sixty thousand troops to the southern Tibetan, including theconstruction of five airports and advanced landing field. Obviously thisbehavior undermines the trust between the two countries. Aggressive as a resultof India, China announced the establishment of commando inTibet!

 

 

 

 

 

The commando consists of N snipers.Messages show that Indian will send airborne to our Border. Our Army organizesthe commando ambushing in the mountains.

A sniper can only hit the target in hisfield of vision. And will not be able to hit the target outside his field ofvision

As the captain of the commando, how willyou show your talent to win the battle?

 

 

 

 

Input

The input consists of several test cases.The first line of each case contains two integers N, M (1<=N<=50,1<=M<=1000), N representing the number of snipers, M representing thenumber of airborne. The next line contains N numbers (Hi,(1<=i<=N)),representing each sniper’s field of vision.(the field of vision Hi means thatthe sniper can only see the target higher than or equal to Hi meters), The nextM lines contain a pair of integers(Ai,Hi) each, representing the airborne i(1<=i<=M) begin to fall at the moment Ai, and from the heightHi,(1<=Ai<=100,1<=Hi<=500).

We assume that each airborne falls onemeter per second, a sniper can only hit one target per second.

 

 

 

Output

Output the maximum number of airborne thesniper team can hit.

 

 

Sample Input

2 5

1 9

1 2

1 2

1 2

2 2

2 4

 

 

Sample Output

4

 

 

Source

2009 Multi-University Training Contest 7 -Host by FZU

 

 

Recommend

gaojie

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

int a[60];
typedef struct data
{
    int ai,hi;
    bool t;
}LIST;
LIST b[1100];
int cmp(LIST x,LIST y)
{
    return x.ai<y.ai;
}
int cmp3(int x,int y)
{
    return x>y;
}
int find(LIST x[1100],int y,int time,int z)
{
    int i,j=-1;
    int min=32767;
    for(i=0;i<y;i++)
    {
        if(x[i].ai==time&&x[i].t==true&&x[i].hi>=z&&x[i].hi<min)
        {
            min=x[i].hi;j=i;
        }
    }
    return j;
}
int main()
{
    int n,m,i,j,s;
    int sum,curtime;
    for(;;)
    { 
        if(scanf("%d %d",&n,&m)==EOF) break;
        sum=0;
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
        for(i=0;i<m;i++)
        {
            scanf("%d %d",&b[i].ai,&b[i].hi);b[i].t=true;
        }
        sort(b,b+m,cmp);sort(a,a+n,cmp3);
        curtime=b[0].ai;
        for(;;curtime++)
        {
            for(i=0;i<n;i++)//寻找目标
            {
                s=find(b,m,curtime,a[i]);
                if(s>=0)
                {
                    sum++;b[s].t=false;
                }
            }
            int num=0;
            for(i=0;i<m;i++)//更新数据
            {
                if(b[i].t==true&&b[i].ai<=curtime)
                {
                    b[i].ai++;b[i].hi--;
                }
                for(j=0;j<n;j++)
                {
                    if(b[i].hi>=a[j]&&b[i].t==true) break;
                }
                if(j==n) num++;
            }
            if(num==m) break;
        }
        printf("%d\n",sum);
    }
    return 0;
}



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值