POJ 3544 贪心 Journey with Pigs

题目链接:http://poj.org/problem?id=3544

分析:目标状态是总的最大利润,不难想到,如果知道每个地方单位重量的利润,那我们只要利润最大的地方卖最重的,则总利润肯定最大.而现在已知只是单价只要再减去单位重量的成本(运费),就能得到单位重量的利润.题目自然就简单了!

 

#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
const int maxn=1005;

struct node {
    int k;///编号
    __int64 w;
} f[maxn];

struct maxp {
    int k;///编号
    __int64 d;
} p[maxn];

int g[maxn];

bool cmp(node x,node y) {
    return x.w>y.w;
}

bool cmp1(maxp x,maxp y) {
    return x.d>y.d;
}

int main() {
    __int64 n,t,q;
    cin>>n>>t;
    for(int i=1; i<=n; ++i) {
        f[i].k=i;
        cin>>f[i].w;
    }
    for(int i=1; i<=n; ++i) {
        p[i].k=i;
        cin>>p[i].d;///i地到原地的距离
    }
    for(int i=1; i<=n; ++i) {
        cin>>q;
        p[i].d=q-p[i].d*t;///转换成i地到原地的每斤肉的利润
    }
    sort(f+1,f+n+1,cmp);///对n个地方的每斤肉利润从大到小排序
    sort(p+1,p+n+1,cmp1);///对n头猪的重量排序
    for(int i=1; i<=n; ++i)
        g[p[i].k]=f[i].k;
    for(int i=1; i<=n; ++i) {
        cout<<g[i];
        if(i!=n)cout<<' ';
    }
    cout<<endl;
    return 0;
}


 

 

posted @ 2013-05-03 19:40  javawebsoa  Views(172)  Comments(0Edit  收藏  举报