FatMouse's Speed

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7213    Accepted Submission(s): 3181
Special Judge

Problem Description
FatMouse
believes that the fatter a mouse is, the faster it runs. To disprove
this, you want to take the data on a collection of mice and put as large
a subset of this data as possible into a sequence so that the weights
are increasing, but the speeds are decreasing.
 
Input
Input contains data for a bunch of mice, one mouse per line, terminated by end of file.

The
data for a particular mouse will consist of a pair of integers: the
first representing its size in grams and the second representing its
speed in centimeters per second. Both integers are between 1 and 10000.
The data in each test case will contain information for at most 1000
mice.

Two mice may have the same weight, the same speed, or even the same weight and speed.

 
Output
Your
program should output a sequence of lines of data; the first line
should contain a number n; the remaining n lines should each contain a
single positive integer (each one representing a mouse). If these n
integers are m[1], m[2],..., m[n] then it must be the case that

W[m[1]] < W[m[2]] < ... < W[m[n]]

and

S[m[1]] > S[m[2]] > ... > S[m[n]]

In order for the answer to be correct, n should be as large as possible.
All
inequalities are strict: weights must be strictly increasing, and
speeds must be strictly decreasing. There may be many correct outputs
for a given input, your program only needs to find one.

 
Sample Input
6008 1300
6000 2100
500 2000
1000 4000
1100 3000
6000 2000
8000 1400
6000 1200
2000 1900
                       //EOF结束用ctrl+z
Sample Output
4
4
5
9
7
分析:实际上是让求 单调递增序列的,双向的
AC代码:
 #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
struct node //老鼠的属性
{
int w; //体重
int s; //速度
int x; //输入时的顺序号
}mice[];
int cmp(node a,node b) //以体重为标准,将老鼠按体重递减排序
{
return a.w<b.w;
}
int main()
{
int n=;
int i,j;
int much[],head[]; //分别记录第i只老鼠为止,子序列长度与前驱存储位置(mice数组中下标)
while(scanf("%d %d",&mice[n].w,&mice[n].s)!=EOF)
mice[n].x=n+,n++;
sort(mice,mice+n+,cmp); //排序
head[]=-; //终止标记
much[]=;
int max1=,x; //由第一只老鼠到当前检索位置为止,子序列的最大长度和其前驱位置在前驱记录数组head中的下标
for(i=;i<=n;i++)
{
head[i]=-;
much[i]=;
for(j=;j<i;j++)
{
if(mice[i].w>mice[j].w && mice[i].s<mice[j].s && much[j]+>much[i]) //体重严格递增,速度严格递减,子序列更长
{
much[i]=much[j]+;
head[i]=j;
if(much[i]>max1) //前驱处理
{
max1=much[i];
x=i; }
//cout<<"i="<<i<<"j="<<j<<endl;
} }
}
//cout<<"X==="<<x<<endl;
int road[];
i=;
while() //处理路劲记录
{
//cout<<"X="<<mice [x].x<<endl;
road[i++]=mice[x].x;
//cout<<x<<" "<<head[x]<<endl;
x=head[x];
if(x==-)
break;
}
printf("%d\n",max1);
for(i--;i>=;i--)
printf("%d\n",road[i]);
return ;
}
 

hdoj1160 FatMouse's Speed 动态规划的更多相关文章

  1. hdu FatMouse's Speed 动态规划DP

    动态规划的解决方法是找到动态转移方程. 题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3&sectionid ...

  2. [HDOJ1160]FatMouse's Speed(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse believes that the fatter a mouse is, th ...

  3. HDU 1160 FatMouse's Speed 动态规划 记录路径的最长上升子序列变形

    题目大意:输入数据直到文件结束,每行两个数据 体重M 和 速度V,将其排列得到一个序列,要求为:体重越大 速度越低(相等则不符合条件).求这种序列最长的长度,并输出路径.答案不唯一,输出任意一种就好了 ...

  4. HDU - 1160 FatMouse's Speed 动态规划LIS,路径还原与nlogn优化

    HDU - 1160 给一些老鼠的体重和速度 要求对老鼠进行重排列,并找出一个最长的子序列,体重严格递增,速度严格递减 并输出一种方案 原题等于定义一个偏序关系 $(a,b)<(c.d)$ 当且 ...

  5. HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. FatMouse's Speed——J

    J. FatMouse's Speed FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...

  7. HDU 1160 FatMouse's Speed(要记录路径的二维LIS)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. HDU 1160 FatMouse's Speed (DP)

    FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

  9. FatMouse's Speed(HDU LIS)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. 使用web_url注意Resource的选项

    在使用web_url的时候,一定注意Resource的使用,一般最好使用Resource=0,如果使用Resource=1,那么一定要修改配置. Resource Attribute If Resou ...

  2. PHP $_POST

    $_POST 变量用于收集来自 method="post" 的表单中的值. $_POST 变量 $_POST 变量是一个数组,内容是由 HTTP POST 方法发送的变量名称和值. ...

  3. Vue 生命周期LIFECYCLE是8个吗?

    vue生命周期钩子个数是:11个. export const LIFECYCLE_HOOKS = [ 'beforeCreate', 'created', 'beforeMount', 'mounte ...

  4. netsh学习

    show allowedprogram –显示被允许的程序配置 show config - 显示防火墙的配置 show currentprofile -显示 Windows 防火墙的当前配置文件. s ...

  5. linux 挂载硬件设备

    mount命令用于挂载文件系统,格式为:“mount 文件系统 挂载目录”. 挂载是在使用硬件设备前的最后操作的一步,只需要用mount命令把硬件设备与一个目录做关联,然后就能在这个目录中看到硬件设备 ...

  6. 用Canvas为网页加入动态背景

    近期刚刚接到为微信公众帐号"玩转三里屯"制作首页的任务. 考虑到页面仅仅在手机中浏览.并且手机对canvas的支持又很好,所以打算使用canvas做点不一样的动画. 首先来看下效果 ...

  7. 使用 Feed43

    1.打开 Feed43 2.将标题.链接,时间等变化的字段删去用 {%} 代替.将固定且多余的字段删去用 {*} 代替.注意,源码中有换行的地方均需要添加{*} . 3.活学活用

  8. iOS UIKit Dynamics入门 UIKit动力学,实现重力、连接、碰撞、悬挂等动画效果

    本文为转载文章 版权归原文所有 什么是UIKit动力学(UIKit Dynamics) 其实就是UIKit的一套动画和交互体系.我们现在进行UI动画基本都是使用CoreAnimation或者UIVie ...

  9. Java任务调度框架Quartz

    转自:http://blog.csdn.net/yuebinghaoyuan/article/details/9045471  介绍  Quartz is a full-featured, open ...

  10. 理解ROC和AUC

    分类器各种各样,如何评价这些分类器的性能呢?(这里只考虑二元分类器,分类器的输出为概率值) 方法一:概率定义法 从正样本中随机选取元素记为x,从负样本中随机选取元素记为y,x的置信度大于y的概率 计算 ...