首页 > 其他 > 详细

POJ杂题题解

时间:2020-04-23 16:22:01      阅读:43      评论:0      收藏:0      [点我收藏+]

POJ1147

Code

POJ1163

数字三角形,dp入门题。
\(f_{x,y} = max(f_{x+1,y},f_{x+1,y+1}) + a_{x,y}\)

Code
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<set>
#include<queue>
#include<vector>
#include<string>

using namespace std;

#define P system("pause");
#define B printf("Break\n");
#define A(x) cout << #x << " " << (x) << endl;
#define AA(x,y) cout << #x << " " << (x) << " " << #y << " " << (y) << endl;
#define ll long long
#define inf 1000000000
#define linf 10000000000000000

int read()
{
    int x = 0,f = 1;
    char c = getchar();
    while(c < ‘0‘ || c > ‘9‘)
    {
        if(c == ‘-‘) f = -1;
        c = getchar();
    }
    while(c >= ‘0‘ && c <= ‘9‘)
    {
        x = (x << 3) + (x << 1) + c - ‘0‘;
        c = getchar();
    }
    return f * x;
}
#define N 150
int f[N][N],a[N][N],n;
int dfs(int x,int y)
{
    if(f[x][y]) return f[x][y];
    if(x == n) return f[n][y] = a[n][y];
    else return f[x][y] = max(dfs(x + 1,y),dfs(x + 1,y + 1)) + a[x][y];
}
int main()
{
    n = read();
    for(int i = 1;i <= n;++i)
        for(int j = 1;j <= i;++j)
            a[i][j] = read();
    printf("%d\n",dfs(1,1));
}

POJ1922

理性分析一下,发现这个人一定会跟着骑得最快的人一块骑,因此只需统计出最先到达终点的人的时间即可。注意在0时刻之前出发的,要么一定会被这个人超过,要么永远追不上,所以不予考虑。

Code
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<set>
#include<queue>
#include<vector>
#include<string>

using namespace std;

#define P system("pause");
#define B printf("Break\n");
#define A(x) cout << #x << " " << (x) << endl;
#define AA(x,y) cout << #x << " " << (x) << " " << #y << " " << (y) << endl;
#define ll long long
#define inf 1000000000
#define linf 10000000000000000

int read()
{
    int x = 0,f = 1;
    char c = getchar();
    while(c < ‘0‘ || c > ‘9‘)
    {
        if(c == ‘-‘) f = -1;
        c = getchar();
    }
    while(c >= ‘0‘ && c <= ‘9‘)
    {
        x = (x << 3) + (x << 1) + c - ‘0‘;
        c = getchar();
    }
    return f * x;
}
int main()
{
    int n;
    while(~scanf("%d",&n) && n)
    {
        double ans = inf;
        for(int i = 1;i <= n;++i)
        {
            double v,t,dt = inf;
            scanf("%lf%lf",&v,&t);
            if(t >= 0) dt = ceil(t + 4.5 / (v / 3600.0));
            ans = min(ans,dt);
        }
        printf("%d\n",(int)ans);
    }
}

POJ杂题题解

原文:https://www.cnblogs.com/lijilai-oi/p/12759295.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!