HDU 1160 FatMouse's Speed
半个下午,总算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的更多相关文章
- HDU 1160 FatMouse's Speed(要记录路径的二维LIS)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1160 FatMouse's Speed (DP)
FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ...
- HDU - 1160 FatMouse's Speed 动态规划LIS,路径还原与nlogn优化
HDU - 1160 给一些老鼠的体重和速度 要求对老鼠进行重排列,并找出一个最长的子序列,体重严格递增,速度严格递减 并输出一种方案 原题等于定义一个偏序关系 $(a,b)<(c.d)$ 当且 ...
- HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1160 FatMouse's Speed 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 题目意思:给出一堆老鼠,假设有 n 只(输入n条信息后Ctrl+Z).每只老鼠有对应的weigh ...
- HDU 1160 FatMouse's Speed LIS DP
http://acm.hdu.edu.cn/showproblem.php?pid=1160 同样是先按它的体重由小到大排,相同就按speed排就行. 这样做的好处是,能用O(n^2)枚举,因为前面的 ...
- HDU 1160 FatMouse's Speed (sort + dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...
- hdu 1160 FatMouse's Speed (最长上升子序列+打印路径)
Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- HDU - 1160 FatMouse's Speed 【DP】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...
- 题解报告:hdu 1160 FatMouse's Speed(LIS+记录路径)
Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
随机推荐
- POJ 3181 Dollar Dayz (完全背包,大数据运算)
题意:给出两个数,n,m,问1~m中的数组成n,有多少种方法? 这题其实就相当于 UVA 674 Coin Change,求解一样 只不过数据很大,需要用到高精度运算... 后来还看了网上别人的解法, ...
- Javascript 正则表达式笔记2
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- App接口设计思路
http://www.techweb.com.cn/network/system/2016-01-11/2256859.shtml http://www.woshipm.com/pmd/172952. ...
- 网站建设底层知识Socket与Http解析
在进行网站建设的时候,常常遇到不同的协议,Socket和http协议都可以实现数据传输,但两种传输方式在网站建设中有什么各自的特点,和缺点,如何选择合适的传输方式. 1 数据传输方式 1.1 Soc ...
- UVA 11481 - Arrange the Numbers 数学
Consider this sequence {1, 2, 3, . . . , N}, as a initial sequence of first N natural numbers. You ca ...
- MongoDB (一) MongoDB 介绍
MongoDB 是一个跨平台的,面向文档的数据库,提供高性能,高可用性和可扩展性方便. MongoDB工作在收集和文件的概念. 数据库 数据库是一个物理容器集合.每个数据库都有自己的一套文件系统上的文 ...
- Linux 删除文件夹和文件的命令
linux删除目录很简单,很多人还是习惯用rmdir,不过一旦目录非空,就陷入深深的苦恼之中,现在使用rm -rf命令即可.直接rm就可以了,不过要加两个参数-rf 即:rm -rf 目录名字-r 就 ...
- hadoop 2.0 native
1.安装protobuf,参照http://wiki.apache.org/hadoop/HowToContribute 安装java模块 在java目录mvn install 2.配置protobu ...
- lintcode: 最长无重复字符的子串
题目 最长无重复字符的子串给定一个字符串,请找出其中无重复字符的最长子字符串. 例如,在"abcabcbb"中,其无重复字符的最长子字符串是"abc",其长度为 ...
- iOS开发--正则表达式
目录[-] 正则表达式简单语法总结 一.什么是正则表达式 二.正则表达式的基础语法 1.字面值 2.特殊字符(元字符) (1)句号 (2)字符类([]) (3)区间符号(-) (4)取反符号(^) ( ...