FatMouse's Speed

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24573    Accepted Submission(s): 10896
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


Sample Output


题目大意与分析

给出一堆鼠标的重量与速度,输出一个最长的序列,满足重量越来越大,速度越来越小。

先将鼠标根据重量从小到大排序,再求最大下降子序列就行了。

#include<bits/stdc++.h>

using namespace std;

typedef struct
{
int add;
int w;
int s;
}node;
node a[];
int dp[],anss,i,temp,c[],x,y,num,j,n;
bool cmp(node a,node b)
{
return a.w<b.w;
} int main()
{
while(cin>>x>>y)
{
num++;
a[num].add=num;
a[num].w=x;
a[num].s=y;
}
sort(a+,a++num,cmp);
for(i=;i<=num;i++)
{
dp[i]=;
for(j=;j<i;j++)
{
if(a[j].w<a[i].w&&a[j].s>a[i].s)
dp[i]=max(dp[j]+,dp[i]);
}
if(dp[i]>anss)
anss=dp[i];
}
cout<<anss<<endl;
temp=anss;
for(i=num;i>=;i--)
{
if(dp[i]==temp)
{
temp--;
c[temp]=a[i].add;
}
}
for(i=;i<anss;i++)
cout<<c[i]<<endl; }

HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)的更多相关文章

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

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

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

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

  3. hdu 1160 FatMouse's Speed(最长不下降子序列+输出路径)

    题意: FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to ...

  4. HDU 1160 FatMouse's Speed (sort + dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...

  5. HDU - 1160 FatMouse's Speed 【DP】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...

  6. HDU 1160 FatMouse's Speed(DP)

    点我看题目 题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置. 思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题 ...

  7. HDU - 1160 (FatMouse's Speed )最长上升子序列

    题意:一个元素有两个属性 w 和 sp 求在w严格递增的情况下 sp严格递减 用结构体 定义三个参数  w  sp  ix , ix是在输入时的顺序  因为我们要排序 之后把结构体数组 按从小到大排序 ...

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

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

  9. HDU 1160 FatMouse's Speed (DP)

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

随机推荐

  1. Phaserjs V2的state状态解析及技巧

    用phaserjs开发了好多游戏了,但是对phaser还是了解不深,只知道怎么去用,今天就特意花点时间研究下phaser的状态管理到底是怎么回事. 首先,new Phaser.Game,以下是Phas ...

  2. TOP K和Partition对比

    TOP k算法适用于海量数据,不用一批装入内存.. partition算法需要全部装入内存排序,需要修改原数据..

  3. JavaScript分支结构Ⅱ—switch-case

    ㈠switch-case 使用场合 优先用于等值判断的条件中   ㈡switch-case 语句执行逻辑 switch case语句是一种特殊的分支结构,可以根据一个表达式的不同取值,从不同的程序入口 ...

  4. java8 base64编码和解码

    package com.oy; import java.nio.charset.StandardCharsets; import java.util.Base64; import org.junit. ...

  5. Spring Boot教程(二十八)通过JdbcTemplate编写数据访问

    数据源配置 在我们访问数据库的时候,需要先配置一个数据源,下面分别介绍一下几种不同的数据库配置方式. 首先,为了连接数据库需要引入jdbc支持,在pom.xml中引入如下配置: <depende ...

  6. [pytorch笔记] 调整网络学习率

    1. 为网络的不同部分指定不同的学习率 class LeNet(t.nn.Module): def __init__(self): super(LeNet, self).__init__() self ...

  7. php 将几个变量合为数组,变量名和值对应

    <?php $firstname = "Bill"; $lastname = "Gates"; $age = "60"; $resul ...

  8. JS框架_(JQuery.js)动画效果鼠标跟随

    百度云盘 传送门 密码 :4n9u 火狐浏览器上纯CSS_动画效果鼠标跟随效果: (作者:lily_lcj 传送门) <!DOCTYPE html PUBLIC "-//W3C//DT ...

  9. Pandas使用groupby()时是否会保留顺序?

    PythonPandas:使用groupby()和agg()时是否保留了顺序? 看到这个增强问题 简短的答案是肯定的,groupby会保留传入的顺序.你可以用你的例子来证明这一点: df = pd.D ...

  10. Docker入门-常用命令

    Docker镜像操作 Docker运行容器前需要本地存在对应的镜像,如果本地不存在该镜像,Docker会从镜像仓库下载该镜像. 获取镜像 从Docker镜像仓库获取镜像的命令是docker pull. ...