zoukankan      html  css  js  c++  java
  • POJ 1946 Cow Cycling

    Cow Cycling
    Time Limit: 1000MS   Memory Limit: 30000K
    Total Submissions: 2516   Accepted: 1396

    Description

    The cow bicycling team consists of N (1 <= N <= 20) cyclists. They wish to determine a race strategy which will get one of them across the finish line as fast as possible. 

    Like everyone else, cows race bicycles in packs because that's the most efficient way to beat the wind. While travelling at x laps/minute (x is always an integer), the head of the pack expends x*x energy/minute while the rest of pack drafts behind him using only x energy/minute. Switching leaders requires no time though can only happen after an integer number of minutes. Of course, cows can drop out of the race at any time. 

    The cows have entered a race D (1 <= D <= 100) laps long. Each cow has the same initial energy, E (1 <= E <= 100). 

    What is the fastest possible finishing time?

    Only one cow has to cross the line. The finish time is an integer. Overshooting the line during some minute is no different than barely reaching it at the beginning of the next minute (though the cow must have the energy left to cycle the entire minute). N, D, and E are integers.

    Input

    A single line with three integers: N, E, and D 

    Output

    A single line with the integer that is the fastest possible finishing time for the fastest possible cow. Output 0 if the cows are not strong enough to finish the race. 

    Sample Input

    3 30 20
    

    Sample Output

    7
    

    Hint

    [as shown in this chart:
    
    	                            leader E
    
    	               pack  total used this
    
    	time  leader  speed   dist   minute
    
    	  1      1      5       5      25
    
    	  2      1      2       7       4
    
    	  3      2*     4      11      16
    
    	  4      2      2      13       4
    
    	  5      3*     3      16       9
    
    	  6      3      2      18       4
    
    	  7      3      2      20       4
    
    	* = leader switch

    Source


        我发现近期理解题意,真是该死,我理解成了最后仅仅能有一头牛通过,这样其它的牛除最后一头牛外最后的能量必须是负值。老是WA后。发现思路没错,就怀疑理解错题意。果然他要求的是仅仅要一头牛通过即可,求这头牛的最快时间,其它的牛不做要求。改了改初始话,AC了
    题意:给定N头牛,每头牛的能量为E,距离为D,跑的时候假设是速度为X,则打头的牛的能量消耗为X*X/minute 其它的牛的能量消耗为X/minute 求当中一头牛到达终点时候,所用时间最少

    思路:预处理出dp1[sta][end][e]:表示在能量为e的时候要跑的长度为sta,跑了end的时候用的时间最少
    然后dfs+记忆化DP,枚举每头牛跑的长度。
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <cmath>
    #define N 110
    #define INF 0x7ffffff
    using namespace std;
    int dp1[N][N][N];
    int dp[N][N][N];
    bool ch[N][N][N];
    int main()
    {
        //freopen("data.txt","r",stdin);
        int dfs(int n,int m,int k);
        int n,m,k;
        while(scanf("%d %d %d",&n,&m,&k)!=EOF)
        {
            for(int i=0;i<=k;i++)
            {
                for(int j=0;j<=i;j++)
                {
                    for(int z = 0;z<=m;z++)
                    {
                        dp1[i][j][z]=INF;
                    }
                }
            }
            for(int z= 0;z<=m;z++)
            {
                dp1[0][0][z] = 0;
            }
            for(int i=1;i<=k;i++)
            {
                for(int j=0;j<=m;j++)
                {
                    dp1[i][0][j] = 0;
                }
            }
            for(int i=1;i<=k;i++)
            {
                for(int j=1;j<=i;j++)
                {
                    for(int z=1;z<=m;z++)
                    {
                        for(int v=1;v*v<=z&&v<=j;v++)
                        {
                            dp1[i][j][z] = min(dp1[i][j][z],dp1[i-v][j-v][z-v*v]+1);
                        }
                    }
                }
            }
            memset(ch,false,sizeof(ch));
            dfs(n,k,m);
            if(dp[n][k][m]>=INF)
            {
                printf("0
    ");
            }else
            {
                printf("%d
    ",dp[n][k][m]);
            }
        }
        return 0;
    }
    int dfs(int n,int m,int k)
    {
        if(ch[n][m][k])
        {
            return dp[n][m][k];
        }
        if(n==1)
        {
            ch[n][m][k] = true;
            dp[n][m][k] = dp1[m][m][k];
            return dp1[m][m][k];
        }
        int Min = INF;
        for(int i=0;i<=m;i++)
        {
            if(dp1[m][i][k]!=INF)
            {
                int w = dfs(n-1,m-i,k-i);
                Min = min(Min,w+dp1[m][i][k]);
            }
        }
        ch[n][m][k] = true;
        dp[n][m][k] = Min;
        return Min;
    }
    



查看全文
  • 相关阅读:
    爬取1907条『课程学习』数据,分析哪类学习资源最受大学生青睐
    以『B站』为实战案例!手把手教你掌握爬虫必备框架『Scrapy』
    python爬取各类基金数据,以『动图可视化』方式展示基金的涨跌情况
    详细实战教程!部署Flask网站+域名访问+免费https证书
    王者荣耀白晶晶皮肤1小时销量突破千万!分析网友评论我发现了原因
    python爬取『大年初一』热映电影,以『可视化及词云秀』方式带你了解热映电影...
    python爬取44130条用户观影数据,分析挖掘用户与电影之间的隐藏信息!
    Nanopore sequencing and assembly of a human genome with ultra-long reads
    Genome Sequencing and Assembly by Long Reads in Plants
    SiLiCO: A Simulator of Long Read Sequencing in PacBio and Oxford Nanopore
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10837637.html
  • Copyright © 2011-2022 走看看