hdu2881 2010.3.6

来源:互联网 发布:linux git clone 编辑:程序博客网 时间:2024/06/07 04:05

hdu2881 2010.3.6

 

DP  哈密顿距离 最多完成多少任务

 

TLE:刚开始用自己写的qosrt,结果超时,后来用函数库里的sort就ac了~~~


#include <cstdio>#include <cmath>#include <algorithm>using namespace std;#define MAXN 1000+10#define MAXM 10000+10struct node{int x,y,t,num;} f[MAXM];int n,m;int cmp(struct node x,struct node y){return x.t<y.t;}int main(){while (scanf("%d %d",&n,&m),n!=0,m!=0){int i,j,ans=0;for(i=1;i<=m;i++){scanf("%d %d %d",&f[i].t,&f[i].x,&f[i].y);f[i].num=0;};sort(f,f+m,cmp);for(i=1;i<=m;i++){for(j=1;j<i;j++)if (abs(f[i].x-f[j].x) + abs(f[i].y-f[j].y) <= f[i].t-f[j].t)if (f[j].num>f[i].num)f[i].num=f[j].num;f[i].num++;if (f[i].num>ans) ans=f[i].num;}printf("%d\n",ans);}return 0;}

Jack's struggle

Time Limit: 10000/5000 MS(Java/Others)    Memory Limit:65535/65535 K (Java/Others)

Total Submission(s): 702    Accepted Submission(s): 266

 

 

Problem Description

A team of airborne troops are ready tocomplete some missions.

The battlefield was divided into a grid ofn*n, this team can be air-dropped at any place on time 0. In every time unitafter landing, they can go to the grid left, right, up or down to the currentgrid, or they can just stay.

On their mission list, each mission isdescribed as three integers: t, r and c, represents a task that must becompleted exactly at time t on the grid (r, c).

Obviously, with limits of time, not allmissions can be done.

The captain, Jack, struggling makingdecisions, 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 nand m, 1<=n<=1000, 1<=m<=10000, n represents the size of thebattlefield and m represents the number of missions on the list.

 

* Following m lines, each one describes amission 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 themaximum number of mission that can be completed.

 

 

Sample Input

2 2

1 1 1

2 2 2

0 0

 

 

Sample Output

1

 

 

Source

2009 Multi-University Training Contest 8 -Host by BJNU

 

 

Recommend

gaojie

 



0 0
原创粉丝点击