zoukankan      html  css  js  c++  java
  • HDU 1160 FatMouse's Speed

    FatMouse's Speed

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6276    Accepted Submission(s): 2735 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
     
    Source
     
    Recommend
    Ignatius
     
     
     
     
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    
    using namespace std;
    
    const int maxn=10010;
    
    struct node{
        int id;
        int weight;
        int speed;
        int pre;
        int len;
    }mouse[maxn];
    
    int cmp(const struct node &a,const struct node &b){
        if(a.weight!=b.weight)
            return a.weight<b.weight;
        return a.speed<b.speed;
    }
    
    void output(int k){
        if(mouse[k].len==1)
            printf("%d\n",mouse[k].id);
        else{
            output(mouse[k].pre);
            printf("%d\n",mouse[k].id);
        }
    }
    
    int main(){
    
        //freopen("input.txt","r",stdin);
    
        int cnt=0;
        while(scanf("%d%d",&mouse[cnt].weight,&mouse[cnt].speed)!=EOF){
            mouse[cnt].id=cnt+1;
            //mouse[cnt].pre=cnt;
            mouse[cnt].len=1;
            cnt++;
        }
        sort(mouse,mouse+cnt,cmp);
        int i,j;
        for(i=0;i<cnt;i++)
            for(j=0;j<i;j++)
                if(mouse[i].weight>mouse[j].weight && mouse[i].speed<mouse[j].speed)
                    if(mouse[i].len<mouse[j].len+1){
                        mouse[i].len=mouse[j].len+1;
                        mouse[i].pre=j;
                    }
        int max=0;
        for(i=0;i<cnt;i++)
            if(mouse[max].len<mouse[i].len)
                max=i;
        printf("%d\n",mouse[max].len);
        output(max);
        return 0;
    }
  • 相关阅读:
    kafka 学习资料
    kafka 的 docker 镜像使用
    SpringBoot 使用 Mybatis 注解进行一对多和多对多查询(不推荐使用注解方式)
    MYSQL 中的 int(11) 到底代表什么意思?
    MyBatis 学习资料
    什么是 CAP 理论?
    一致性哈希算法原理
    SELECT 语句语法
    MySQL中如何实现 select top n
    基于 debian:stretch-slim 系统镜像的 docker 镜像,安装 curl
  • 原文地址:https://www.cnblogs.com/jackge/p/2982712.html
Copyright © 2011-2022 走看看