zoukankan      html  css  js  c++  java
  • HDOJ --- 1160

    FatMouse's Speed

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 8334    Accepted Submission(s): 3715
    Special Judge


    Problem 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

     思路:DP水,先排序,然后直接比较。

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstdio>
     4 #include<stack>
     5 #include<cstring>
     6 #define MAX 1111
     7 using namespace std;
     8 class mouse{
     9     public:
    10         int w, v, id;
    11         bool operator < (const mouse &a) const{
    12             return w < a.w;
    13         }
    14 };
    15 mouse m[MAX];
    16 int dp[MAX], pre[MAX];
    17 stack<int>s;
    18 int main(){
    19     int ans = 0, i = 1, j, k;
    20     /* freopen("in.c", "r", stdin); */
    21     while(~scanf("%d%d", &m[i].w, &m[i].v)) m[i].id = i, ++i;
    22     while(!s.empty()) s.pop();
    23     sort(m+1, m+i);
    24     for(int j = 1;j < i;j ++) dp[j] = 1;
    25     memset(pre, 0, sizeof(pre));
    26     m[0].w = m[0].v = 0;
    27     for(j = 1;j < i;j ++){
    28         for(k = 0;k < j;k ++){
    29             if(m[j].w > m[k].w && m[j].v < m[k].v){
    30                 if(dp[j] < dp[k] + 1){
    31                     dp[j] = dp[k] + 1;
    32                     pre[j] = k;
    33                 }
    34             }
    35         }
    36     }
    37     for(k = 1;k < i;k ++){
    38         if(ans < dp[k]){
    39             ans = dp[k];
    40             j = k;
    41         }
    42     }
    43     printf("%d
    ", ans);
    44     s.push(m[j].id);
    45     for(k = j;m[pre[k]].id;k = pre[k]) s.push(m[pre[k]].id);
    46     while(!s.empty()){
    47         printf("%d
    ", s.top());
    48         s.pop();
    49     }
    50     return 0;
    51 }
  • 相关阅读:
    Silverlight 2中实现文件上传和电子邮件发送
    Silverlight结合Web Service进行文件上传
    silverlight DataGrid 内嵌ComboBox 实现加载和保存
    silverlight 使用IValueConverter 转换
    检测场所条件查询
    代码中的坏味道
    Prism初研究之Bootstrapper
    Prism初研究之简介
    编写可读代码的艺术
    ffmpeg怎么样处理网络流
  • 原文地址:https://www.cnblogs.com/anhuizhiye/p/3630364.html
Copyright © 2011-2022 走看看