POJ 3544 Journey with Pigs

Posted SomnusMistletoe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ 3544 Journey with Pigs相关的知识,希望对你有一定的参考价值。

题意:有一个人有n头猪,他在从A镇到B镇的n个村庄中每个村庄卖一头猪,每个村庄猪的价格不同,有运费,问他最多能卖多少钱、

分析:很容易想到猪运的越远所花路费越多,因此每个村庄猪的实际售价实质等于猪的收购价-从A镇运到该镇的路费。

首先算出每个村庄的实际售价,剩下的就是匹配问题,当然猪的重量与村庄的实际售价成正比赚钱越多。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) a < b ? a : b
#define Max(a, b) a < b ? b : a
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
const double pi = acos(-1.0);
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 1000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int ans[MAXN];
struct P1
{
    int id;
    ll w;
    bool operator < (const P1 & a)const
    {
        return w > a.w;
    }
} num1[MAXN];
struct P2
{
    int id;
    ll d, p, real;
    bool operator < (const P2 & a)const
    {
        return real > a.real;
    }
} num2[MAXN];
int main()
{
    int n;
    ll t;
    while(scanf("%lld%lld", &n, &t) == 2)
    {
        for(int i = 0; i < n; ++i)
        {
            scanf("%lld", &num1[i].w);
            num1[i].id = i + 1;
        }
        for(int i = 0; i < n; ++i)
            scanf("%lld", &num2[i].d);
        for(int i = 0; i < n; ++i)
        {
            num2[i].id = i + 1;
            scanf("%lld", &num2[i].p);
            num2[i].real = num2[i].p - num2[i].d * t;
        }
        sort(num1, num1 + n);
        sort(num2, num2 + n);
        for(int i = 0; i < n; ++i)
        {
            ans[num2[i].id] = num1[i].id;
        }
        for(int i = 1; i <= n; ++i)
        {
            if(i > 1) printf(" ");
            printf("%d", ans[i]);
        }
        printf("\n");
    }
    return 0;
}

 

以上是关于POJ 3544 Journey with Pigs的主要内容,如果未能解决你的问题,请参考以下文章

poj2488 A Knight's Journey

A Knight's Journey POJ - 2488

[POJ 1935] Journey

POJ 2488 A Knight's Journey

POJ1935 Journey(树形dp)

POJ2488A Knight's Journey[DFS]