半个下午,总算A过去了

毕竟水题

好歹是自己独立思考,debug,然后2A过的

我为人人的dp算法

题意:

为了支持你的观点,你需要从给的数据中找出尽量多的数据,说明老鼠越重速度越慢这一论点

本着“指针是程序员杀手”这一原则,我果断用pre来表示这只老鼠的直接前驱的序号

代码中我是按体重从大到小排序,然后找出一条最长的体重严格递减速度严格递增的“链”(其实找到的是链尾)。

然后输出的时候从后往前输出

对结构体排序

对于样例来说,循环完以后应该是这样的:

order 2 3 4 8 1 5 7 0 6
weight  500 1000 1100 2000 6000 6000 6000 6008 8000
speed  2000 4000 3000 1900 2100 2000 1200 1300 1400
lenth 1 1 2 3 3 3 4 4 4
pre -1 -1 3 4 4 4 8 8 8

pre == -1代表没有前驱。

 //#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; struct Mouse
{
int order;
int weight;
int speed;
int pre;
int lenth;
}mice[]; int a[]; bool cmp1(Mouse a, Mouse b)
{
if(a.weight != b.weight)
return (a.weight > b.weight);
return (a.speed < b.speed);
} bool cmp2(Mouse a, Mouse b)
{
return (a.order < b.order);
} int main(void)
{
#ifdef LOCAL
freopen("1160in.txt", "r", stdin);
#endif int cnt = ;
int w, s;
while(scanf("%d%d", &w, &s) == )
{
mice[cnt].weight = w;
mice[cnt].speed = s;
mice[cnt].order = cnt;
++cnt;
} sort(mice, mice+cnt, cmp1);
int i, j;
for(i = ; i < cnt; ++i)
{
mice[i].lenth = ;
mice[i].pre = -;
}
//我为人人
for(i = ; i < cnt; ++i)
{
for(j = ; j < i; ++j)
{
if(mice[j].weight > mice[i].weight
&& mice[j].speed < mice[i].speed
&& mice[j].lenth+ > mice[i].lenth)
{
mice[i].lenth = mice[j].lenth + ;
mice[i].pre = mice[j].order;
}
}
} sort(mice, mice+cnt, cmp2);
int maxlen = ;
for(i = ; i < cnt; ++i)
if(mice[i].lenth > mice[maxlen].lenth)
maxlen = i;
int l = mice[maxlen].lenth;
printf("%d\n%d\n", l, maxlen+); int p = maxlen;
for(i = ; i < l; ++i)
{
printf("%d\n", mice[p].pre+);
p = mice[p].pre;
}
return ;
}

代码君

HDU 1160 FatMouse's Speed的更多相关文章

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

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

  2. HDU 1160 FatMouse's Speed (DP)

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

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

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

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

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

  5. hdu 1160 FatMouse's Speed 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 题目意思:给出一堆老鼠,假设有 n 只(输入n条信息后Ctrl+Z).每只老鼠有对应的weigh ...

  6. HDU 1160 FatMouse's Speed LIS DP

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

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

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

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

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

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

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

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

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

随机推荐

  1. svg琐碎01

    svg中的<g>主要用来做分组的定位,使用transform="translate(xOffset,yOffset)" 更改起始坐标. transform中的坐标是相对 ...

  2. Java对象初始化详解

    在Java中,一个对象在可以被使用之前必须要被正确地初始化,这一点是Java规范规定的.本文试图对Java如何执行对象的初始化做一个详细深入地介绍(与对象初始化相同,类在被加载之后也是需要初始化的,本 ...

  3. MJRefresh插件引起的错误

    添加的头部或者尾部刷新,离开这个界面的时候需要移除 - (void)dealloc {    [_tableView removeHeader];} 不同版本的处理的方式不同 报的错误: 类的一个实例 ...

  4. 社交APP经典死法18种,听野路子产品菜狗怎么说

    点这里 社交APP经典死法18种,听野路子产品菜狗怎么说 时间 2015-04-06 11:24:53  虎嗅网相似文章 (4)原文  http://www.huxiu.com/article/112 ...

  5. Cygwin,Mingw

    MinGW vs Cygwin MinGW是Minimalistic GNU for Windows的缩写,也就是Win版的GCC. Cygwin则是全面模拟了Linux的接口,提供给运行在它上面的的 ...

  6. poj 3613(经过N条边的最短路)

    题目链接:http://poj.org/problem?id=3613 思路:我们知道如果矩阵A表示经过1条边的方案数,那么A^N矩阵就代表这经过N条边的方案数,而本题中要求经过N条边的最短距离,于是 ...

  7. SpringMVC深入探究(1)——DispatcherServlet与初始化主线

    在上一篇文章中,我们给出了构成SpringMVC应用程序的三要素以及三要素的设计过程.让我们来归纳一下整个设计过程中的一些要点: SpringMVC将Http处理流程抽象为一个又一个处理单元 Spri ...

  8. linux下修改tomcat的默认目录

    1.修改tomcat的默认目录.它的默认目录是webapps/ROOT,对应的conf目录下的server.xml里的内容是: 1.修改tomcat的默认目录.它的默认目录是webapps/ROOT, ...

  9. IIS7 ASP.NET 未被授权访问所请求的资源

    IIS7 ASP.NET 未被授权访问所请求的资源 ASP.NET 未被授权访问所请求的资源.请考虑授予 ASP.NET 请求标识访问此资源的权限. ASP.NET 有一个在应用程序没有模拟时使用的基 ...

  10. jquery.lazyload用法

    lazyload是jquery的插件,作为延迟加载图片,减压服务器压力. 如何使用: 先把 <script src="jquery.js" type="text/j ...