hdu2881 2010.3.6

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+10

struct 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值