FatMouse's Speed

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 20803    Accepted Submission(s): 9227
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

Sample Output

4
4
5
9
7

题意

有若干老鼠,每个老鼠都有体重和奔跑的速度。找到一个最长的老鼠序列,使老鼠的体重递增,速度递减,并输出这些老鼠的编号

思路

将老鼠的体重按照递增顺序排序,然后查找符合题目要求的老鼠序列,同时记录下老鼠排序之后的老鼠的编号。然后找到最长序列中的最后一个老鼠(体重最小,速度最大),然后递归寻找就行了

AC代码

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ull unsigned long long
#define ms(a) memset(a,-1,sizeof(a))
#define pi acos(-1.0)
#define INF 0x7f7f7f7f
#define lson o<<1
#define rson o<<1|1
const double E=exp(1);
const int maxn=1e6+10;
const int mod=1e9+7;
using namespace std;
int dp[maxn];
// vis[i]=j 表示序列中第i个老鼠的前一个老鼠是第j个老鼠
int vis[maxn];
struct wzy
{
int weight,speed;
int id;
}p[maxn];
bool cmp(wzy u,wzy v)
{
return u.weight>v.weight;
}
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
int k=0;
while(cin>>p[k].weight>>p[k].speed)
{
p[k].id=k+1;
dp[k]=1;
k++;
}
sort(p,p+k,cmp);
int ans=0;
int res;
ms(vis);
for(int i=0;i<k;i++)
{
for(int j=0;j<i;j++)
{
if(p[i].weight<p[j].weight&&p[i].speed>p[j].speed)
{
if(dp[i]<dp[j]+1)
{
dp[i]=dp[j]+1;
vis[i]=j;
}
}
}
if(dp[i]>ans)
{
ans=dp[i];
res=i;
}
}
cout<<ans<<endl;
// res=-1时表示该序列已经输出完全
while(res!=-1)
{
cout<<p[res].id<<endl;
// 更新老鼠编号
res=vis[res];
}
return 0;
}

HDU 1160:FatMouse's Speed(LIS+记录路径)的更多相关文章

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

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

  2. HDU 1160 FatMouse's Speed LIS DP

    http://acm.hdu.edu.cn/showproblem.php?pid=1160 同样是先按它的体重由小到大排,相同就按speed排就行. 这样做的好处是,能用O(n^2)枚举,因为前面的 ...

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

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

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

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

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

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

  6. HDU 1160 FatMouse's Speed (DP)

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

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

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

  8. 题解报告:hdu 1160 FatMouse's Speed(LIS+记录路径)

    Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...

  9. 【最长上升子序列记录路径(n^2)】HDU 1160 FatMouse's Speed

    https://vjudge.net/contest/68966#problem/J [Accepted] #include<iostream> #include<cstdio> ...

  10. hdu 1160 FatMouse's Speed (最长上升子序列+打印路径)

    Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...

随机推荐

  1. android studio 安装步骤

    1◆ jdk环境安装 2◆ android文件下载 3◆ 安装步骤 waiting ---       4◆ 配置   正在安装加速器·····     google setProxy https:/ ...

  2. Ubuntu下环境变量的设置

    远程登录时,不是ssh登陆:  xrdp 可以修改并添加 /etc/xrdp/startwm.sh 代码: #!/bin/sh if [ -r /etc/default/locale ]; then  ...

  3. linux下iostat命令详解

    iostat用于输出CPU和磁盘I/O相关的统计信息 iostat语法 用法:iostat [ 选项 ] [ <时间间隔> [ <次数> ]] 常用选项说明: -c:只显示系统 ...

  4. git开发过程的配置和使用

    git开发过程的使用 1.创建仓库 2.新建项目,填写项目名称等信息 3.初始化仓库,创建git仓库 git init 4.配置个人信息(配置过可忽略) git config --global use ...

  5. linux系统管理 vi编辑器

    Vim是vi improved的缩写是vi的改进版本,vi被认为是事实上的标准编辑器 所有版本的Linux都带有vi编辑器 占用的资源少 与ed,ex等其他编辑器相比,vi对用户更加友好 进入vi编辑 ...

  6. Win10系列:UWP界面布局基础7

    2.附加属性 有一些XAML元素,其自身的属性大多是在其它的元素中声明和使用的,该元素本身却很少使用,这些在其他元素中声明和使用的属性被称为附加属性(Attached Properties).附加属性 ...

  7. 简单选择排序(Simple Selection Sort)

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  8. 【转载】java对象和byte数组互转,直接拿去用

    //加了了Optional防止空指针异常,加入了泛型,省去了强制转化 import java.io.*; import java.util.Optional; /** * Created by Jas ...

  9. Linux系统管理常用命令用法总结(2)

    1.free指令会显示内存的使用情况,包括实体内存,虚拟的交换文件内存,共享内存区段,以及系统核心使用的缓冲区等. 语法:free [-bkmotV][-s <间隔秒数>] 参数说明: - ...

  10. DevExpress WinForms使用教程:WinForms Fluent Design和Acrylic Effects

    在先前的版本发布中,宣布支持Fluent Design Form和Acrylic effects——旨在复制Microsoft下一代UI metaphor的新功能.本文主要介绍如何实现此功能,并明确说 ...