2014
02-17

# Jack’s struggle

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.

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.

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.

2 2
1 1 1
2 2 2
0 0 

1

yf说是天上掉馅饼的二维形式，恩确实如此

#include"stdio.h"
#include"string.h"
#include"algorithm"
#include"cmath"
#define N 10001
using namespace std;

struct node
{
int t,x,y;
}A[N];

int cmp(node a,node b){return a.t<b.t;}
int max(int a,int b){return a>b?a:b;}

int main()
{
int n,m;
int dp[N];
int i,j,ans;
while(scanf("%d%d",&n,&m)!=-1&&(n+m))
{
for(i=0;i<m;i++)
scanf("%d%d%d",&A[i].t,&A[i].x,&A[i].y);
sort(A,A+m,cmp);
ans=0;
for(i=0;i<m;i++)
{
dp[i]=1;
for(j=0;j<i;j++)
{
if(abs(A[i].t-A[j].t)>=(abs(A[i].x-A[j].x)+abs(A[i].y-A[j].y)))
dp[i]=max(dp[i],dp[j]+1);
}
if(dp[i]>ans)ans=dp[i];
}
printf("%d\n",ans);
}
return 0;
}

1. 学算法中的数据结构学到一定程度会乐此不疲的，比如其中的2－3树，类似的红黑树，我甚至可以自己写个逻辑文件系统结构来。