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

    FatMouse’s Speed

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 15613 Accepted Submission(s): 6886
    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

    贪心+记录·路径
    题意:证明体重增加,速度减小,输出最长的例子的大小;和路径。

    #include<stdio.h>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    const int maxn=1010;
    struct node
    {
        int x, y;
        int st;
    } num[maxn];//记录大小和位置
    int cmp(node a,node b)//排序
    {
        if(a.x==b.x)
            return a.y>b.y;
        else
            return a.x<b.x;
    }
    struct lu
    {
        int st,xt;
    } q[maxn];//记录位置和上一个位置
    int dp[maxn];
    int flag;
    void print(int i)
    {
        if(q[i].xt)
            print(q[i].xt);
        else
        {
            flag=1;
            printf("%d
    ",q[i].st);
            return ;
        }
        if(flag)
        {
            printf("%d
    ",q[i].st);
            return ;
        }
    }
    int main()
    {
        int a,b;
        int ps=1;
        while(~scanf("%d%d",&a,&b))
            num[ps].x=a,num[ps].y=b,num[ps].st=ps,ps++;
        sort(num,num+ps,cmp);
        for(int i=0; i<ps; i++)
            dp[i]=1,q[i].st=num[i].st;
        for(int i=2; i<ps; i++)
            for(int j=i-1; j>0; j--)
                if(num[i].x>num[j].x&&num[i].y<num[j].y&&dp[i]<dp[j]+1)
                {
                    dp[i]=dp[j]+1;
                    q[i].xt=j;
                }
        int maxx=0,k=0;
        flag=0;
        for(int i=0; i<ps; i++)
            if(maxx<dp[i])
                maxx=dp[i],k=i;
        printf("%d
    ",maxx);
        print(q[k].xt);
        printf("%d
    ",q[k].st);
        return 0;
    }
    
    "No regrets."
  • 相关阅读:
    暑假N天乐【比赛篇】 —— 2019牛客暑期多校训练营(第二场)
    莫比乌斯反演入门解析
    暑假N天乐【比赛篇】 —— 2019牛客暑期多校训练营(第一场)
    暑假N天乐 —— 多重+分组背包及变形
    暑假N天乐 —— 完全背包及变形
    暑假N天乐【比赛篇】 —— 牛客假日团队赛6
    暑假N天乐 —— 01背包及变形
    离线线段树 SPOJ
    [Python]数据类型、常量、变量和运算符(未完待续)
    [Python]从哪里开始学习写代码(未完待续)
  • 原文地址:https://www.cnblogs.com/zxy160/p/7215139.html
Copyright © 2011-2022 走看看