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. ORACLE NVL 和 NVL2 函数的使用

    NVL函数是一个空值转换函数,在SQL查询中主要用来处理null值.在不支持 null 值或 null 值无关紧要的情况下,可以使用 NVL( ) 来移去计算或操作中的 null 值. Oracle在 ...

  2. HDUOj Ignatius and the Princess III 题目1002

     母函数  组合数学 #include<stdio.h> int c1[125]; int c2[125]; int main() { int n,i,j,k; while(scanf ...

  3. js时间转换,能够把时间转换成yyyymmdd格式或yyyymm格式

    //type为1则转换成yyyymmdd格式,type为2则转换成yyyymm格式 function formatTime(time,type){ var temp_time=new Number(t ...

  4. SSO之安装CAS Server

    JA-SIG CAS(Central Authentication Service)为Web应用系统提供了单点登录服务.它的特性包括:一个开放和具有很好文档支持的协议:一个Java开源服务器组件:提供 ...

  5. npm换国内淘宝镜像

    来源于:http://yijiebuyi.com/blog/b12eac891cdc5f0dff127ae18dc386d4.html 为什么要换源? npm 官方站点 http://www.npmj ...

  6. .NET的多种事务处理

    Oracle 的事务操作,有时候想在批量操作数据集合的时候,执行一次失败,即为了避免数据异常,将所有的操作回滚..NET给我们提供了良好的事务操作,Oracle端也有事务操作,可以灵活使用,此处介绍. ...

  7. 基于JavaScript 声明全局变量的三种方式

    本文转自脚本之家:http://www.jb51.net/article/36548.htm JS中声明全局变量主要分为显式声明或者隐式声明下面分别介绍. 声明方式一: 使用var(关键字)+变量名( ...

  8. Python 绘图库的使用:matplotlib

    Matplotlib 官方API地址:https://matplotlib.org/ 例子: import matplotlib.pyplot as plt num_list=[1.5,0.6,7.8 ...

  9. editplus发布3.01 Build 446 Final版(附下载及中文版)

    http://www.cnblogs.com/JustinYoung/archive/2008/04/14/editplus-301.html没有什么好说的,我个人最喜欢的编辑器.除了windows和 ...

  10. 【jQuery】页面顶部显示的进度条效果

    <!Doctype html> <html> <head> <title>页面顶部显示的进度条效果</title> <meta htt ...