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;
    }
  • 相关阅读:
    Java大坑之Integer对象比较相等
    Spark操作算子本质-RDD的容错
    Spark集群搭建(local、standalone、yarn)
    Spark持久化策略
    SparkRDD内核
    Spark初识
    Hadoop集群初始化启动
    centos6.5安装MySQL5.7
    学习笔记-Kuaihu(仿知乎日报)
    Eclipse开发Android程序如何在手机上运行
  • 原文地址:https://www.cnblogs.com/jackge/p/2982712.html
Copyright © 2011-2022 走看看