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. Codeforces Round #375 (Div. 2) ABCDE

    A - The New Year: Meeting Friends 水 #include<iostream> #include<algorithm> using namespa ...

  2. HDU 4861 Couple doubi (数论 or 打表找规律)

    Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...

  3. JSF 2 multiple select listbox example

    In JSF, <h:selectManyListbox /> tag is used to render a multiple select listbox – HTML select ...

  4. eclispe输入@注解时提示所有注解的设置

    修改输入@提示所有的注解提示方法 eclipse下windows-->preference-->java-->editor-->Content Assist下的Enable a ...

  5. Linux下常用的shell命令记录

     硬件篇 CPU相关 lscpu #查看的是cpu的统计信息. cat /proc/cpuinfo #查看CPU信息详细信息,如每个CPU的型号,主频等 内存相关 free -m #概要查看内存情况 ...

  6. 新网注册域名如何转向其他(如花生壳)DNS(不会报错,已经转入成功)

    最近在玩域名,发现相比较来说,新网的域名注册费用相对廉价好多. 但是我以前是用花生壳的,用惯了花生壳,就觉得新网的域名管理界面很不适应,并不是新网的不好,而是习惯了花生壳. 那么如何将新网注册的域名D ...

  7. JAVA 反射应用:properties2Object

    MixAll.java import java.lang.reflect.Method; import java.util.Properties; public class MixAll { /** ...

  8. iOS开发代码规范

    1.关于命名 1.1统一要求 含义清楚, 尽量做到不需要注释也能了解其作用,若做不到,就加注释 使用全称不使用缩写 1.2类的命名 大驼峰式命名:每一个单词的首字母都采用大写字母例子: MFHomeP ...

  9. FloatingActionButton的一点学习感悟

    最近在学习android材料设计的新控件,前面一篇文章讲到 CoordinatorLayout 结合几个新控件可以实现的几个效果.其中第一个是,Coordinatorlayout + Floating ...

  10. NOSQL之旅---HBase

    最近因为项目原因,研究了Cassandra,Hbase等几个NoSQL数据库,最终决定采用HBase.在这里,我就向大家分享一下自己对HBase的理解. 在说HBase之前,我想再唠叨几句.做互联网应 ...