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

USACO 2002 February

我发现最近理解题意,真是该死,我理解成了最后只能有一头牛通过,这样其他的牛除最后一头牛外最后的能量必须是负值,老是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\n");
        }else
        {
            printf("%d\n",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;
}

POJ 1946 Cow Cycling,布布扣,bubuko.com

时间: 2024-10-10 04:21:46

POJ 1946 Cow Cycling的相关文章

poj 1964 Cow Cycling(dp)

/* 一开始想的二维的 只维护第几只牛还有圈数 后来发现每只牛的能量是跟随每个状态的 所以再加一维 f[i][j][k]表示第i只牛 领跑的j全 已经消耗了k体力 转移的话分两类 1.换一只牛领跑 那么就从f[i][j][k]转移到f[i+1][j][j] 2.不换 那就枚举i领跑几圈l f[i][j-l][k-l*l]转移到f[i][j][k] 时间++ */ #include<iostream> #include<cstdio> #include<cstring>

poj 1985 Cow Marathon 【树的直径】

题目:poj 1985 Cow Marathon 题意:给出一个树,让你求树的直径. 分析: 树的直径:树上两点之间的最大距离. 我们从任意一点出发,BFS一个最远距离,然后从这个点出发,在BFS一个最远距离,就是树的直径. AC代码: /* POJ:1985 Cow Marathon 2014/10/12/21:18 Yougth*/ #include <cstdio> #include <iostream> #include <algorithm> #include

POJ 3613 Cow Relays 恰好n步的最短路径

http://poj.org/problem?id=3613 题目大意: 有T条路,从s到e走n步,求最短路径. 思路: 看了别人的... 先看一下Floyd的核心思想: edge[i][j]=min(edge[i][j],edge[i][k]+edge[k][j]) i到j的最短路是i到j的直接路径或者经过k点的间接路径,但是矩阵的更新总是受到上一次更新的影响 如果每次的更新都存进新矩阵,那么edge[i][k]+edge[k][j]是不是表示只经过三个点两条边的路径呢? min(edge[i

poj 3270 Cow Sorting 置换群 简单题

假设初始状态为 a:2 3 1 5 4 6 则目标状态为 b:1 2 3 4 5 6且下标为初始状态中的3 1 2 4 5 6(a[3],a[1]...) 将置换群写成循环的形式 (2,3,1),(5,4),6就不用移动了. 移动方式2种 1:选循环内最小的数和其他len-1个数交换 2:选整个序列最小的数和循环内最小的数交换,转到1,再换回来. #include<cstdio> #include<queue> #include<algorithm> #include&

poj 3270 Cow Sorting(初涉置换群)

http://poj.org/problem?id=3270 大致题意:给出n个整数,要将它们转化成递增序列,每交换其中两个数的代价是这两个数之和.问排序成功后的最小代价. 该题考察的是置换群知识.在黑书p247上有详细的讲解.总结下置换群,方便复习. 群:给定一个集合G={a,b,c...}和集合G上的二元运算 ·,如果满足封闭性,结合律,存在单位元和逆元,则成集合G在运算'·'之下是一个群. 置换:n个元素1,2,....,n之间的置换可表示为  1     2     3     ...

poj 3348 Cow 凸包面积

Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8122   Accepted: 3674 Description Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they are f

poj 3660 Cow Contest(warshall算法)

poj 3660 Cow Contest Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique among the co

矩阵十题【十】 poj 3613 Cow Relays

题目链接:http://poj.org/problem?id=3613 题目大意: 输入N,T,S,E,N表示要走的边数,T表示一共有几条边,S表示开始的点,E表示结束的点 给出一张无向连通图,求S到E经过N条边的最短路. N (2 ≤ N ≤ 1,000,000) T (2 ≤ T ≤ 100) (1 ≤ I1i ≤ 1,000; 1 ≤ I2i ≤ 1,000) 1 ≤ lengthi  ≤ 1,000 题目主要的思想就是用矩阵的乘法模拟出Floyd进行运算,是个很好的题目. //k步最短路

POJ 2375 Cow Ski Area(强连通)

POJ 2375 Cow Ski Area 题目链接 题意:给定一个滑雪场,每个点能向周围4个点高度小于等于这个点的点滑,现在要建电缆,使得任意两点都有路径互相可达,问最少需要几条电缆 思路:强连通缩点,每个点就是一个点,能走的建边,缩点后找入度出度为0的个数的最大值就是答案,注意一开始就强连通了答案应该是0 代码: #include <cstdio> #include <cstring> #include <stack> #include <algorithm&