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 = ;
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=;i<=m;i++){
scanf("%d%d%d",&g[i].t,&g[i].r,&g[i].c);
}
sort(g+,g+m+,cmp);
int ans = -;
for(int i=;i<=m;i++){
dp[i]=;
for(int j=;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]+>dp[i]) dp[i] = dp[j]+;
}
ans = max(ans,dp[i]);
}
printf("%d\n",ans);
}
return ;
}

最新文章

  1. Highcharts 总结
  2. 数往知来C#之 String 集合 深拷与浅拷 序列化&lt;五&gt;
  3. bnuoj 1071 拼图++(BFS+康拓展开)
  4. Unity3D中读取CSV文件
  5. 【学习opencv第六篇】图像的反转操作
  6. PHP xdebug的安装
  7. C#有关虚方法要知道的知识点:
  8. BBS的登陆——发帖——回帖
  9. 第54章 身份资源 - Identity Server 4 中文文档(v1.0.0)
  10. SVN 提示clean up 进入死循环
  11. jquery 根据文本设置选中某个选项
  12. render函数(转)
  13. qml: 支持的基本类型
  14. 查看局域网指定IP的电脑名
  15. python之tkinter使用-多选框实现开关操作
  16. BP
  17. Django 操作Mysql数据库
  18. 微信小程序选择并上传图片
  19. POJ--2406Power Strings+KMP求字符串最小周期
  20. Linux基础命令---comm

热门文章

  1. Linux之同步互斥阻塞20160703
  2. Nginx的配置文件简介及在Nginx中配置基于不同ip的虚拟主机
  3. POJ3694:Network(并查集+缩点+lca)
  4. [实战篇入门]01-POI读Excel
  5. 阿里C++研发实习二面和三面面经
  6. UVA 808 Bee Breeding (坐标法)
  7. 51Nod 1024 矩阵中不重复的元素 | 技巧 数学
  8. Jmeter-12-如何使用Plugin Manager
  9. AWK文本分析工具-常用场景(持续更新中)
  10. Spring 框架的设计理念与设计模式分析(山东数漫江湖)