FatMouse's Speed

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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
 
 
思路:二次排序后求LIS
 #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_SIZE 1005 struct x
{
int weight;
int speed;
int num,sum,front;
}DP[MAX_SIZE]; int comp(const void * a,const void * b);
int main(void)
{
int i = ;
int max,max_loc,ans,ans_loc;
int box[MAX_SIZE]; while(scanf("%d%d",&DP[i].weight,&DP[i].speed) != EOF)
{
DP[i].num = i;
DP[i].sum = ;
DP[i].front = -;
i ++;
} qsort(DP,i,sizeof(struct x),comp); ans_loc = ;
ans = ;
for(int j = ;j < i;j ++)
{
max = ;
for(int k = ;k < j;k ++)
if(DP[j].weight > DP[k].weight && DP[j].speed < DP[k].speed)
if(DP[k].sum > max)
{
max = DP[k].sum;
max_loc = k;
} DP[j].sum += max;
if(max)
DP[j].front = max_loc; if(ans < DP[j].sum)
{
ans = DP[j].sum;
ans_loc = j;
}
} box[] = ans_loc;
i = ;
while(box[i] != -)
{
i ++;
box[i] = DP[box[i - ]].front;
} printf("%d\n",ans);
for(i --;i >= ;i --)
printf("%d\n",DP[box[i]].num + ); return ;
} int comp(const void * a,const void * b)
{
if((*(struct x *)a).weight == (*(struct x *)b).weight)
return (*(struct x *)b).speed - (*(struct x *)a).speed;
return (*(struct x *)a).weight - (*(struct x *)b).weight;
}

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

  1. HDU 1160 FatMouse's Speed(DP)

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

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

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

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

    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 (最长上升子序列)

    题目链接 题意:n个老鼠有各自的重量和速度,要求输出最长的重量依次严格递增,速度依次严格递减的序列,n最多1000,重量速度1-10000. 题解:按照重量递增排序,找出最长的速度下降子序列,记录序列 ...

  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 【DP】

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

  9. HDU 1160 FatMouse's Speed ——(DP)

    又是那个lis变形的题目. 但是不好定义严格的比较符号,因此只能n^2去做.值得注意的一个是要先排序,因为可能可以先选后面的再选前面的,先排序的话就能够避免这个问题.但是要注意,因为要输出路径,所以要 ...

随机推荐

  1. 报表服务框架:WEB前端UI

    1.Highcharts 2.ECharts 3.ichartjs 参考: http://v1.hcharts.cn/index.php http://echarts.baidu.com/ http: ...

  2. Spring dependency checking with @Required Annotation

    Spring's dependency checking in bean configuration file is used to make sure all properties of a cer ...

  3. [C语言 - 3] 字符串

    字符数组 char * 看做一个特殊的字符数组, 在字符串结束为止添加'\0'结束符 (ASCII码0), 没有\0结尾的是普通的字符数组. 使用双引号定义的字符串自动在尾部加上\0 puts(s)函 ...

  4. Umbraco中的Member登录时的Lock out功能

    请参看文章 https://our.umbraco.org/forum/using-umbraco-and-getting-started/76389-preventing-member-lock-o ...

  5. Ioc容器Autofac系列(3)-- 三种注册组件的方式

    简单来说,所谓注册组件,就是注册类并映射为接口,然后根据接口获取对应类,Autofac将被注册的类称为组件. 虽然可像上篇提到的一次性注册程序集中所有类,但AutoFac使用最多的还是单个注册.这种注 ...

  6. OpenNebula Restfull 接口请求示例

    Fri Jun 20 07:28:20 2014 [I]: 10.0.2.2 - - [20/Jun/2014 07:28:20] "POST /vmtemplate HTTP/1.1&qu ...

  7. MyEclipse10.7的 at com.genuitec.eclipse.ast.deploy.core.Deployment.<init>

      前两天由于换了MyEclipse新版本之后,我的MyEclipse的Servers就不能正常使用了,也就是不能发布Web项目了.出现了空指针的异常,并产生了这个错误: atcom.genuitec ...

  8. C#-datagriview的表头高度的设置

  9. cdoj 1250 喵哈哈的矩阵 数学题

    喵哈哈的矩阵 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1250 Desc ...

  10. zoj3672 Gao The Sequence

    原地踏步了半年,感觉一切都陌生了~ 题意:a[i]-一个任意的数,这个数要等于a[1]~a[i-1]每个数减去任意一个数,经过多次这样的变换到达目标b序列,能到达就yes不能到达距no. 一开始各种分 ...