FatMouse's Speed

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

Appoint description: 
prayerhgq  (2015-07-28)
System Crawler  (2015-09-05)

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
 
 
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <string>
  4. #include <queue>
  5. #include <vector>
  6. #include <map>
  7. #include <algorithm>
  8. #include <cstring>
  9. #include <cctype>
  10. #include <cstdlib>
  11. #include <cmath>
  12. #include <ctime>
  13. #include <climits>
  14. using namespace std;
  15.  
  16. const int SIZE = ;
  17. struct Node
  18. {
  19. int pos;
  20. int weight,speed;
  21. int front,num;
  22. }DP[SIZE];
  23.  
  24. bool comp(const Node & r_1,const Node & r_2);
  25. int main(void)
  26. {
  27. int count = ;
  28.  
  29. while(scanf("%d%d",&DP[count].weight,&DP[count].speed) != EOF)
  30. {
  31. DP[count].pos = count;
  32. DP[count].num = ;
  33. count ++;
  34. }
  35. sort(DP,DP + count,comp);
  36.  
  37. int max = ,max_loc = ;
  38. for(int i = ;i < count;i ++)
  39. {
  40. DP[i].front = i;
  41. for(int j = ;j < i;j ++)
  42. if(DP[i].weight > DP[j].weight && DP[i].speed < DP[j].speed)
  43. if(DP[i].num < DP[j].num)
  44. {
  45. DP[i].num = DP[j].num;
  46. DP[i].front = j;
  47. if(max < DP[i].num + )
  48. {
  49. max = DP[i].num + ;
  50. max_loc = i;
  51. }
  52. }
  53. DP[i].num ++;
  54. }
  55.  
  56. int temp[SIZE];
  57. count = ;
  58. while()
  59. {
  60. temp[count] = max_loc;
  61. if(max_loc == DP[max_loc].front)
  62. {
  63. count ++;
  64. break;
  65. }
  66. max_loc = DP[max_loc].front;
  67. count ++;
  68. }
  69. printf("%d\n",max);
  70. for(int i = count - ;i >= ;i --)
  71. printf("%d\n",DP[temp[i]].pos + );
  72.  
  73. return ;
  74. }
  75.  
  76. bool comp(const Node & r_1,const Node & r_2)
  77. {
  78. return r_1.weight < r_2.weight;
  79. }

怒刷DP之 HDU 1160的更多相关文章

  1. 怒刷DP之 HDU 1257

    最少拦截系统 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  2. 怒刷DP之 HDU 1260

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

  3. 怒刷DP之 HDU 1176

    免费馅饼 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status  ...

  4. 怒刷DP之 HDU 1087

    Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64 ...

  5. 怒刷DP之 HDU 1114

    Piggy-Bank Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit S ...

  6. 怒刷DP之 HDU 1069

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  7. 怒刷DP之 HDU 1024

    Max Sum Plus Plus Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. 怒刷DP之 HDU 1029

    Ignatius and the Princess IV Time Limit:1000MS     Memory Limit:32767KB     64bit IO Format:%I64d &a ...

  9. HDU 1160 DP最长子序列

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

随机推荐

  1. 网页布局:float与position的区别

    网页开发中布局是一个永恒的话题.巧妙的布局会让网页具有良好的适应性和扩展性.css的布局主要涉及两个属性——position和float.它们俩看上去很容易被弄混,可是仔细分析一下,它们的区别还是很明 ...

  2. Quartz.NET 2.0 学习笔记(1) :Quartz.NET简介

    http://www.cnblogs.com/lzrabbit/archive/2012/04/13/2447609.html

  3. java静态代理与动态代理简单分析

    原创作品,可以转载,但是请标注出处地址http://www.cnblogs.com/V1haoge/p/5860749.html 1.动态代理(Dynamic Proxy) 代理分为静态代理和动态代理 ...

  4. 栈的应用-四则表达式(C#代码实现)

    ->概念 中缀表达式 9+(3-1)*3+10/2 转换步骤 9 + 9 + ( 9 3 + ( - 9 3 1 + ( - ) 9 3 1 - + 9 3 1 - + * 9 3 1 - 3 ...

  5. 【C#】工具类-FTP操作封装类FTPHelper

    转载:http://blog.csdn.net/gdjlc/article/details/11968477 using System; using System.Collections.Generi ...

  6. LVS 单独完成--负载均衡

    原文地址:http://blog.sina.com.cn/s/blog_5f54f0be0101eyiu.html LVS 是通过 IPVS 模块来实现的.IPVS是LVS集群的核心,主要用于完成用户 ...

  7. window.location.href的使用方法

    http://hljqfl.blog.163.com/blog/static/40931580201122210573364/ 在写ASP.Net程序的时候,我们常常遇到跳转页面的问题,我们常常使用R ...

  8. 关于javaScript注册事件传递参数的浅析

    最近这半年作为一个java 程序员,我写的javaScript代码都快比java代码多了,前段时间是给某银行做一个柜员管控系统,在柜员授权这一块功能上,由于柜员的授权需要考虑各方面的因素,比如机构权限 ...

  9. 制作Windows的ico图标

    也不知道这个方法是不是最好的,有时间再查看其它方法 首先设计出图标,png格式即可. 使用一款软件 IconWorkshop 下载了一个试用版,临时制作够用了 制作步骤如下: 1.打开png图片 2. ...

  10. Linux文件时间属性

    Linux文件时间属性                                                                                         ...