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. Java IO (2) - OutputStream

    Java IO (2) - OutputStream 前言 JavaIO一共包括两种,一种是stream,一种是reader/writer,每种又包括in/out,所以一共是四种包.Java 流在处理 ...

  2. eclispe输入@注解时提示所有注解的设置

    修改输入@提示所有的注解提示方法 eclipse下windows-->preference-->java-->editor-->Content Assist下的Enable a ...

  3. [iOS UI进阶 - 3.2] 手势识别器UIGestureRecognizer

    A.系统提供的手势识别器   1.敲击手势 UITapGestureRecognizer numberOfTapsRequired: 敲击次数 numberOfTouchesRequired: 同时敲 ...

  4. java commons-lang 工具包 逃脱工具 转unicode 及其他

    <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</ar ...

  5. poj3041

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12162   Accepted: 6620 Descri ...

  6. HDU/杭电2013多校第三场解题报告

    今天悲剧了,各种被虐啊,还是太年轻了 Crime 这道题目给的时间好长,第一次就想到了暴力,结果华丽丽的TLE了. 后来找了一下,发现前24个是1, 2, 6, 12, 72, 72, 864, 17 ...

  7. 一个简洁通用的调用DLL函数的帮助类

    本次介绍一种调用dll函数的通用简洁的方法,消除了原来调用方式的重复与繁琐,使得我们调用dll函数的方式更加方便简洁.用过dll的人会发现c++中调用dll中的函数有点繁琐,调用过程是这样的:在加载d ...

  8. [置顶] 异步加载图片,使用LruCache和SD卡或手机缓存,效果非常的流畅

    转载请注明出处http://blog.csdn.net/xiaanming/article/details/9825113 异步加载图片的例子,网上也比较多,大部分用了HashMap<Strin ...

  9. C++ Button右键弹出式菜单

    Button右键弹出式菜单 关键点 用类来实现 的 实现过程 新建1个类  类名CButtonPopMenu 基类CButton 新建1个菜单资源 IDR_MENU1 // ButtonPopMenu ...

  10. TreeView节点拖拉操作1

      TreeView节点拖拉操作1 //事先设置 TreeView1.DragMode= dmAutomatic;   unit Unit1; interface uses   Windows, Me ...