Journey with Pigs
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3004   Accepted: 922

Description

Farmer John has a pig farm near town A. He wants to visit his friend living in town B. During this journey he will visit n small villages so he decided to earn some money. He tooks n pigs and plans to sell one pig in each village he visits.

Pork prices in villages are different, in the j-th village the people would buy a pork at pj rubles per kilogram. The distance from town A to the j-th village along the road to town B is dj kilometers.

Pigs have different weights. Transporting one kilogram of pork per one kilometer of the road needs t rubles for addition fuel.

Help John decide, which pig to sell in each town in order to earn as much money as possible.

Input

The first line of the input file contains integer numbers n (1 ≤ n ≤ 1000) and t (1 ≤ t ≤ 109). The second line contains n integer numbers wi (1 ≤ wi ≤ 109) — the weights of the pigs. The third line contains n integer numbers dj (1 ≤ dj ≤ 109) — the distances to the villages from the town A. The fourth line contains n integer numbers pj (1 ≤ pj ≤ 109) — the prices of pork in the villages.

Output

Output n numbers, the j-th number is the number of pig to sell in the j-th village. The pigs are numbered from 1 in the order they are listed in the input file.

Sample Input

3 1
10 20 15
10 20 30
50 70 60

Sample Output

3 2 1

思路:
问题中每斤猪肉被出售到第j个村庄的利润为:猪肉单价 - 路费单价 * 路程;第一行按照猪的质量从小到大排序的数;第二行按照利润从小到大排序的数;
两行数相互相乘所有积的和有这样的规律:逆序积的和 <= 乱序积的和 <= 顺序积的和(这是一种贪心的思想)。
具体步骤如下:
step1:根据输入计算每斤猪肉被出售到第j个村庄的利润(猪肉单价 - 路费单价 * 路程)。
step2:将每斤猪肉被出售到第j个村庄的利润与每只猪的质量进行从小到大排序,则对应位置的猪出售到对应位置编号的村庄。
 #include <iostream>
#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std; typedef struct{
LL value;
int postion;
}Node; Node weight[], earn[]; bool cmp(Node a, Node b){
return a.value < b.value;
} int main(){
int n, i;
LL t;
while(scanf("%d %lld", &n, &t) != EOF){
for(i = ; i <= n; i++){
scanf("%lld", &weight[i].value);
weight[i].postion = i;
}
LL dis[];
for(i = ; i <= n; i++){
scanf("%lld", &dis[i]);
} for(i = ; i <= n; i++){
LL x;
scanf("%lld", &x);
earn[i].value = x - dis[i] * t;
earn[i].postion = i;
} sort(weight + , weight + n + , cmp);
sort(earn + , earn + n + , cmp); int ans[]; for(i = ; i <= n; i++)
ans[earn[i].postion] = weight[i].postion; for(i = ; i < n; i++)
printf("%d ", ans[i]);
printf("%d\n", ans[n]);
}
return ;
}
 

poj 3544 Journey with Pigs的更多相关文章

  1. Problem J. Journey with Pigs

    Problem J. Journey with Pigshttp://codeforces.com/gym/241680/problem/J考察排序不等式算出来单位重量在每个村庄的收益,然后生序排列猪 ...

  2. [POJ 1935] Journey

    Link: POJ1935 传送门 Solution: 一道吓唬人的水题 注意这是一棵树,两点间仅有唯一的路径! 于是每个“关键点”和起点只有一条路径,想去起点另一棵子树上的节点必须要回到起点 如果必 ...

  3. A过的题目

    1.TreeMap和TreeSet类:A - Language of FatMouse ZOJ1109B - For Fans of Statistics URAL 1613 C - Hardwood ...

  4. poj 1149 Pigs 网络流-最大流 建图的题目(明天更新)-已更新

    题目大意:是有M个猪圈,N个顾客,顾客要买猪,神奇的是顾客有一些猪圈的钥匙而主人MIRKO却没有钥匙,多么神奇?顾客可以在打开的猪圈购买任意数量的猪,只要猪圈里有足够数量的猪.而且当顾客打开猪圈后mi ...

  5. POJ 1149 PIGS(Dinic最大流)

    PIGS Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20738   Accepted: 9481 Description ...

  6. 广大暑假训练1(poj 2488) A Knight's Journey 解题报告

    题目链接:http://vjudge.net/contest/view.action?cid=51369#problem/A   (A - Children of the Candy Corn) ht ...

  7. poj 2488 A Knight&#39;s Journey(dfs+字典序路径输出)

    转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem? id=2488 ----- ...

  8. POJ 2488 -- A Knight's Journey(骑士游历)

    POJ 2488 -- A Knight's Journey(骑士游历) 题意: 给出一个国际棋盘的大小,判断马能否不重复的走过所有格,并记录下其中按字典序排列的第一种路径. 经典的“骑士游历”问题 ...

  9. 网络流 A - PIGS POJ - 1149 最大流

    A - PIGS POJ - 1149 这个题目我开始感觉很难,然后去看了一份题解,写的很好 https://wenku.baidu.com/view/0ad00abec77da26925c5b01c ...

随机推荐

  1. 使用MySQL正则表达式查询

    MySQL用WHERE子句对正则表达式提供了初步的支持,允许你指定用正则表达式过滤SELECT检索出的数据. REGEXP后所跟的东西作为正则表达式处理. 代码 SELECT prod_name FR ...

  2. linux 下安装apache 快速教程

    最近自学linux,看鸟哥的文章.提到了apache,所以在虚拟机redhat 5下安装了一把, 结合国内外文章写下快速可行的教程: --------------------------------- ...

  3. iOS 推送证书

    push 服务器证书 钥匙串:登入-->证书,选项里面导出证书命名为cert.p12,跟密钥命名为key.p12 需要将上面的2个.p12文件转成.pem格式: openssl pkcs12 - ...

  4. SQL Server活动监视器

    打开SQL Server活动监视器:

  5. [AngularJS] Lazy loading Angular modules with ocLazyLoad

    With the ocLazyLoad you can load AngularJS modules on demand. This is very handy for runtime loading ...

  6. [Angular-Scaled Web] 9. Control your promises with $q

    Learn how to manually control how asynchronous requests are handled with the use of promises. Becaus ...

  7. memcpy的用法总结

    1.memcpy 函数用于 把资源内存(src所指向的内存区域) 拷贝到目标内存(dest所指向的内存区域):拷贝多少个?有一个size变量控制拷贝的字节数:函数原型:void *memcpy(voi ...

  8. Android线程和线程池

    Translated From Google Android. class PhotoDecodeRunnable implements Runnable {...    /*     * Defin ...

  9. Metadata Lock原理8

    http://www.kancloud.cn/taobaomysql/monthly/67141 MySQL· 5.7优化·Metadata Lock子系统的优化 背景 引入MDL锁的目的,最初是为了 ...

  10. Python string objects implementation

    http://www.laurentluce.com/posts/python-string-objects-implementation/ Python string objects impleme ...