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. C#应用Newtonsoft.Json操作json

    Newtonsoft.Json是一个开源的C#操作json的项目,应用起来非常简单.其github地址; 下面的代码演示了如何应用Newtonsoft.Json序列号和反序列化. using Newt ...

  2. jdk的wsimport方法实现webservice客户端调用服务

    1.配置好jdk环境,打开命令行,输入wsimport回车能看到很多该命令的参数, -s:要生成客户端代码的存储路径 -p:对生成的代码从新打包 这两个最常用. 在打开的命令行中输入:wsimport ...

  3. 你应该知道的16个Linux服务器监控命令

    在不同的Linux发行版中,会有不同的GUI程序可以显示各种系统信息,比如SUSE Linux发行版中,就有非常棒的图形化的配置和管理工具YaST,KDE桌面环境里的KDE System Guard也 ...

  4. Quality Center 使用IE8异常浏览器打开

    需要装2个软件 1.  Microsoft Visual C++ 2005 Redistributable Package (x64) 2.  dotnetfx35.exe 配置IE的选项 使用兼容模 ...

  5. javascript中document对象的属性和方法

    document.documentElement; document.firstChild;document.childNodes[0];// 取得对<html>的引用document.b ...

  6. String 和 byte[]

    使用默认字符集合 Encodes this String into a sequence of bytes using the platform's default charset, storing ...

  7. 利用CSS3实现页面淡入动画特效

    利用CSS3动画属性"@keyframes "可实现一些动态特效,具体语法和参数可以网上自行学习.这篇文章主要是实践应用一下这个动画属性,实现页面淡入特效,在火狐24版.chrom ...

  8. SQL Server 2008 Data Types and Entity Framework 4

    Because I’ve had a lot of conversations about spatial data types lately, I thought I would create a ...

  9. jsp页面用el表达式获取枚举的code

    jsp页面用el表达式获取枚举的code <c:set var="D_BUSINESS" value="<%=DeptEnum.D_BUSINESS%> ...

  10. 用Eclipse来开发STM32

    先贴一个官方说明文档:http://www.keil.com/support/man/docs/ecluv/default.htm