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. ZooKeeper做独立server执行(上)

    ZooKeeper做独立server执行(上) 作者:chszs.转载需注明.博客主页:http://blog.csdn.net/chszs 一.ZooKeeper安装及配置 版本号:ZooKeepe ...

  2. Android UI-实现底部切换标签(fragment)

    Android UI-实现底部切换标签(fragment) 前言 本篇博客要分享的一个UI效果--实现底部切换标签,想必大家在一些应用上面遇到过这样的效果了,最典型的就是微信了,能够左右滑动切换页面. ...

  3. Android API之android.widget.Filterable

      android.widget.Filterable 定义了一种可过滤的行为.Filterable接口通常有android.widget.Adapter来实现.接口Filterable中有个抽象方法 ...

  4. JavaScript中的闭包(closure)

    闭包的特性 1.函数嵌套函数 2.函数内部可以引用外部的参数和变量 3.参数和变量不会被垃圾回收机制回收  闭包的缺点就是常驻内存,会增大内存使用量,使用不当很容易造成内存泄露,主要用于私有的方法和变 ...

  5. POJ 1364 King (差分约束)

    King Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8660   Accepted: 3263 Description ...

  6. 你的Android不好用,都是因为这几点原因

    Android早已是全球最大.用户最多的移动操作系统,不过它离全球最好用还差得很远. 大家随手就能举出些曾经历过的糟心体验,如手机卡顿!电量不禁用!广告弹窗老是出现!不过很少有人会追根寻底的去问为何如 ...

  7. Redis的Docker镜像

    原文地址:https://hub.docker.com/_/redis/ Pull Command docker pull redis Short Description Redis is an op ...

  8. Ubuntu 10.04 安装Qt4.8.1 源码后字体模糊的问题

    Ubuntu 10.04 安装QT4.8.1 源码后字体模糊的问题. 附加解决 QT SDK 4.8.1 链接失败的问题 Ubuntu 10.04 编译QT源码后,编译程序,运行后IPA字体无法正常显 ...

  9. OGG_GoldenGate数据控制进程Manager(案例)

    2014-03-03 Created By BaoXinjian

  10. qsort函数、sort函数

    先说明一下qsort和sort,只能对连续内存的数据进行排序,像链表这样的结构是无法排序的. 首先说一下, qsort qsort(基本快速排序的方法,每次把数组分成两部分和中间的一个划分值,而对于有 ...