zoukankan      html  css  js  c++  java
  • UVa 12018 Juice Extractor 切水果dp暂时存疑



      Juice Extractor 

    Jerry loses himself in the interesting game: Fruit Ninja. Fruit Ninja is a game of iPhone and iPad in which the players cut the fruits coming from the bottom of the screen and gain the bonus from cutting more than two fruits with a single slice. Once a fruit is cut, it breaks into small pieces and cannot be cut any more.

    After months of training, he becomes pro of this game. Actually, he can cut all the fruits on the screen at any time. Jerry also has a bad habit that he has no willing to leave some fruits for the future cutting. In the other words, after Jerry cuts the fruits, all the fruits on the screen breaks and no one left. That is why all his friends call him `Juice Extractor'.

    Now he only consider about the bonus, when he cuts more than two fruits, he can gain some bonus scores as same as the number of fruits he slice at that time. For example, if Jerry cuts 4 fruits with a single slice, he can get 4 scores from this slice.

    After Jerry gets the fruit schedule, he knows the appearing time and the disappearing time for every single fruit. He can only cut a fruit into pieces between its appearing time and disappearing time inclusive. He wants to know the maximum possible bonus scores he can receive.

    Input 

    There are several test cases; the first line of the input contains a single integer T, denoting the number of the test cases. (T$ \le$200)

    For each test case, the first line contains an integer N, denoting the total number of fruits. ( 1$ \le$N$ \le$1000)

    The next N lines, each line describe a fruit. For each line, there are two integers Xi and Yi, where Xi is the appearing time of the fruit and Yi is the disappearing time of this fruit. ( 0$ \le$Xi$ \le$Yi$ \le$1000000000)

    Output 

    For each test case, output a single integer denoting the maximum scores that Jerry could possibly gain. See the sample for further details.

    Sample Input 

    1
    10
    1 10
    2 11
    3 12
    4 13
    13 14
    14 15
    13 19
    20 22
    21 23
    22 24
    

    Sample Output 

    Case #1: 10
    --------------------------------------

    大体思路很容易想到,但是为什么wa了呢?


    ---------------------------------

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    
    using namespace std;
    
    const int OO=1e9;
    const int maxn=1111;
    
    struct Fruits{
        int x;
        int y;
    };
    
    int n,T;
    int f[maxn];
    Fruits a[maxn];
    
    bool cmp(Fruits a,Fruits b)
    {
        if (a.x==b.x) return a.y<b.y;
        return a.x<b.x;
    }
    
    int main()
    {
        scanf("%d",&T);
        int cas=1;
        while (T--)
        {
            memset(a,0,sizeof(a));
            memset(f,0,sizeof(f));
            scanf("%d",&n);
            for (int i=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].y);
            sort(a+1,a+n+1,cmp);
            int ans=0;
            for (int i=1;i<=n;i++)
            {
                int cut=0;
                if (i+1<=n&&a[i].x==a[i+1].x) continue;//why???????
                for (int j=i;j>=1;j--)
                {
                    if (a[j].y>=a[i].x) cut++;
                    if (cut>2) f[i]=max(f[i],f[j-1]+cut);
                    else f[i]=max(f[i],f[j-1]);
                }
                ans=max(ans,f[i]);
            }
            printf("Case #%d: %d\n",cas++,ans);
        }
        return 0;
    }
    











      Juice Extractor 

    Jerry loses himself in the interesting game: Fruit Ninja. Fruit Ninja is a game of iPhone and iPad in which the players cut the fruits coming from the bottom of the screen and gain the bonus from cutting more than two fruits with a single slice. Once a fruit is cut, it breaks into small pieces and cannot be cut any more.

    After months of training, he becomes pro of this game. Actually, he can cut all the fruits on the screen at any time. Jerry also has a bad habit that he has no willing to leave some fruits for the future cutting. In the other words, after Jerry cuts the fruits, all the fruits on the screen breaks and no one left. That is why all his friends call him `Juice Extractor'.

    Now he only consider about the bonus, when he cuts more than two fruits, he can gain some bonus scores as same as the number of fruits he slice at that time. For example, if Jerry cuts 4 fruits with a single slice, he can get 4 scores from this slice.

    After Jerry gets the fruit schedule, he knows the appearing time and the disappearing time for every single fruit. He can only cut a fruit into pieces between its appearing time and disappearing time inclusive. He wants to know the maximum possible bonus scores he can receive.

    Input 

    There are several test cases; the first line of the input contains a single integer T, denoting the number of the test cases. (T$ \le$200)

    For each test case, the first line contains an integer N, denoting the total number of fruits. ( 1$ \le$N$ \le$1000)

    The next N lines, each line describe a fruit. For each line, there are two integers Xi and Yi, where Xi is the appearing time of the fruit and Yi is the disappearing time of this fruit. ( 0$ \le$Xi$ \le$Yi$ \le$1000000000)

    Output 

    For each test case, output a single integer denoting the maximum scores that Jerry could possibly gain. See the sample for further details.

    Sample Input 

    1
    10
    1 10
    2 11
    3 12
    4 13
    13 14
    14 15
    13 19
    20 22
    21 23
    22 24
    

    Sample Output 

    Case #1: 10
  • 相关阅读:
    判断安卓或是IOS
    安卓、IOS内嵌H5的相互通信
    原生js tab选项卡粗略封装
    关于抓包
    vue学习的第一天——vue-router的相关使用
    关于jQuery插件封装的总结
    mvc生成静态页
    C#调用java代码
    汉字转16进制,汉字转10进制
    Model 类型为dynamic或者list<dynamic>
  • 原文地址:https://www.cnblogs.com/cyendra/p/3038371.html
Copyright © 2011-2022 走看看