zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    HTML5新特性之离线缓存技术
    摘要
    典藏百度前端面试题
    idea连接mysql数据库
    报错:[stack Error: Can't find Python executable "python"] vue项目npm install
    SVN客户端(小乌龟)checkout(检出)文件(项目)到本地
    java日期Date工具类 日期格式转换
    radio标签 onchange事件
    js 写带有返回值的function遇到的返回值不正常的情况
    读取zip包内根目录文件的文件名
  • 原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/6104875.html
Copyright © 2011-2022 走看看