半个下午,总算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. 斌哥的 Docker 进阶指南

    过去的一年中,关于 Docker 的话题从未断过,而如今,从尝试 Docker 到最终决定使用 Docker 的转化率依然在逐步升高,关于 Docker 的讨论更是有增无减.另一方面,大家的注意力也渐 ...

  2. Fbric、Ansible、Docker、Chaos Monkey:DevOps工具的年中回顾

    Fbric.Ansible.Docker.Chaos Monkey:DevOps工具的年中回顾 [编者按]近日,Cyber Engineering Solutions Group 技术经理 Hasan ...

  3. java基础知识回顾之抽象类

    /* 抽象类: 抽象:笼统,模糊,看不懂!不具体. 特点: 1,方法只有声明没有实现时,该方法就是抽象方法,需要被abstract修饰. 抽象方法必须定义在抽象类中.该类必须也被abstract修饰. ...

  4. ExtJs之文本框及数字输入

    结合HTML来理解, 比较容易. <!DOCTYPE html> <html> <head> <title>ExtJs</title> &l ...

  5. 基础DOM和CSS操作(一)

    DOM简介 DOM是一种文档对象模型,方便开发者对HTML结构元素内容进行展示和修改.在JavaScript中,DOM不但内容庞大繁杂,而且我们开发的过程中需要考虑更多的兼容性.扩展性.在jQuery ...

  6. Java集合框架(四)

    Collections    集合框架的工具类    着重讲解以下方法: 1.sort(): 1º根据元素的自然顺序对指定列表按升序进行排序,列表中的所有元素都必须实现comparable接口. pu ...

  7. Java集合框架(一)

    Java中集合类的关系图:  Collection 先来集合中的最大接口——Collection 可以通过查看JDK帮助文档,了解Collection接口中的最共性的方法.通过以下代码示例演示这些方法 ...

  8. js截取指定字节长度的字符串

    默认的截取字符串都是根据字符长度或位置截取的,典型的两个方法是substr和substring. 这样导致的问题是截取同样长度的字符串时,多字节字符(汉字等)和单字节字符(半角英文字母.半角数字)占的 ...

  9. webmatrix

    http://www.microsoft.com/web/webmatrix/ WebMatrix is a free, lightweight, cloud-connected web develo ...

  10. GDB调试方法精粹

    http://blog.chinaunix.net/uid-26922071-id-3756018.html 一.多线程调试 1. 多线程调试,最重要的几个命令: info threads       ...