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

hdu 2881

时间:2016-04-11 18:20:41      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

Jack‘s struggle

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1418    Accepted Submission(s): 471


Problem Description
A team of airborne troops are ready to complete some missions.
The battlefield was divided into a grid of n*n, this team can be air-dropped at any place on time 0. In every time unit after landing, they can go to the grid left, right, up or down to the current grid, or they can just stay.
On their mission list, each mission is described as three integers: t, r and c, represents a task that must be completed exactly at time t on the grid (r, c).
Obviously, with limits of time, not all missions can be done.
The captain, Jack, struggling making decisions, wants to know how many missions they can complete at most.
 

 

Input
The input contains serveral cases:

For each case:

* The first line contains two integers n and m, 1<=n<=1000, 1<=m<=10000, n represents the size of the battlefield and m represents the number of missions on the list.

* Following m lines, each one describes a mission using three integers, t, r and c.


No two missions have the same t, r and c.

The input is terminated by n=m=0.
 

 

Output
One integer in one line represents the maximum number of mission that can be completed.
 

 

Sample Input
2 2 1 1 1 2 2 2 0 0
 

 

Sample Output
1
 
题意:输入n m 代表n*n的矩阵和m条询问,每一条询问有三个变量 t r c 代表在第 t 秒到达(r,c)这个点.
问输入的这些询问中最多达到多少个点.
 
题解:能够在第 t 秒到达从这一点到达下一个点,那么两点之间的最短距离必定不能大于 t ,所以这题对 t排序,然后求最长上升子序列就行了.
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
const int M = 10005;
struct grid{
    int t,r,c;
}g[M];
int dp[M];
int cmp(grid a,grid b){
    return a.t < b.t;
}
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF,n+m){
        for(int i=1;i<=m;i++){
            scanf("%d%d%d",&g[i].t,&g[i].r,&g[i].c);
        }
        sort(g+1,g+m+1,cmp);
        int ans = -1;
        for(int i=1;i<=m;i++){
            dp[i]=1;
            for(int j=1;j<i;j++){
                int usetime = abs(g[i].r-g[j].r)+abs(g[i].c-g[j].c);
                if(usetime<=abs(g[j].t-g[i].t)&&dp[j]+1>dp[i]) dp[i] = dp[j]+1;
            }
            ans = max(ans,dp[i]);
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

hdu 2881

标签:

原文地址:http://www.cnblogs.com/liyinggang/p/5379077.html

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