poj 3544 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的更多相关文章
- Problem J. Journey with Pigs
Problem J. Journey with Pigshttp://codeforces.com/gym/241680/problem/J考察排序不等式算出来单位重量在每个村庄的收益,然后生序排列猪 ...
- [POJ 1935] Journey
Link: POJ1935 传送门 Solution: 一道吓唬人的水题 注意这是一棵树,两点间仅有唯一的路径! 于是每个“关键点”和起点只有一条路径,想去起点另一棵子树上的节点必须要回到起点 如果必 ...
- A过的题目
1.TreeMap和TreeSet类:A - Language of FatMouse ZOJ1109B - For Fans of Statistics URAL 1613 C - Hardwood ...
- poj 1149 Pigs 网络流-最大流 建图的题目(明天更新)-已更新
题目大意:是有M个猪圈,N个顾客,顾客要买猪,神奇的是顾客有一些猪圈的钥匙而主人MIRKO却没有钥匙,多么神奇?顾客可以在打开的猪圈购买任意数量的猪,只要猪圈里有足够数量的猪.而且当顾客打开猪圈后mi ...
- POJ 1149 PIGS(Dinic最大流)
PIGS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20738 Accepted: 9481 Description ...
- 广大暑假训练1(poj 2488) A Knight's Journey 解题报告
题目链接:http://vjudge.net/contest/view.action?cid=51369#problem/A (A - Children of the Candy Corn) ht ...
- poj 2488 A Knight's Journey(dfs+字典序路径输出)
转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem? id=2488 ----- ...
- POJ 2488 -- A Knight's Journey(骑士游历)
POJ 2488 -- A Knight's Journey(骑士游历) 题意: 给出一个国际棋盘的大小,判断马能否不重复的走过所有格,并记录下其中按字典序排列的第一种路径. 经典的“骑士游历”问题 ...
- 网络流 A - PIGS POJ - 1149 最大流
A - PIGS POJ - 1149 这个题目我开始感觉很难,然后去看了一份题解,写的很好 https://wenku.baidu.com/view/0ad00abec77da26925c5b01c ...
随机推荐
- [转]MyEclipse for Spring2014破解
转至:http://blog.my-eclipse.cn/myeclipse-2014-crack.html 一.安装完成MyEclipse2014(适用于2013等版本)后,不要打开软件,下载破解附 ...
- Ubuntu12.04 使用中遇到的问题
这个随笔回记录使用Ubuntu遇到的一些问题 不定期进行整理和分类 1.Question: ubuntu 无法检测包或者源码包 Description:Ubuntu软件中心打开时报错 无法检 ...
- Science上发表的超赞聚类算法(转)
作者(Alex Rodriguez, Alessandro Laio)提出了一种很简洁优美的聚类算法, 可以识别各种形状的类簇, 并且其超参数很容易确定. 算法思想 该算法的假设是类簇的中心由一些局部 ...
- 配置 dovecat 的 PAM
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- MEF 编程指南(四):声明导入
组合部件通过 [System.ComponentModel.Composition.ImportAttribute] 特性声明导入.类似于导出,也有几种不同的方法声明导入,即通过:字段(Fields) ...
- 根据条件自定义 cxGrid 的单元格样式
当指定的单元格需要指定样式(如字体颜色设置为红色,背景色设置为黄色)时,可按如下步骤进行: 1.添加 csStyleRepository 控件,并新建 Style,设置前景(TextColor).背景 ...
- C++ Button右键弹出式菜单
Button右键弹出式菜单 关键点 用类来实现 的 实现过程 新建1个类 类名CButtonPopMenu 基类CButton 新建1个菜单资源 IDR_MENU1 // ButtonPopMenu ...
- S5PV210开发系列四_uCGUI的移植
S5PV210开发系列四 uCGUI的移植 象棋小子 1048272975 GUI(图形用户界面)极大地方便了非专业用户的使用,用户无需记忆大量的命令,取而代之的是能够通过窗体.菜单 ...
- SkinSharp用法
SkinSharp又称Skin#,是很好用的一款轻量化的VC程序美化工具 官网地址是http://www.skinsharp.com/ 尽管SkinSharp是收费软件,但提供试用版,并且比較厚道,试 ...
- error LNK2019: unresolved external symbol / error LNK2001: 无法解析的外部符号
在 vc++ 2008 和 vc++ 2010 编译时分别出现上面的错误.一般这种错误是由于引用函数未定义造成的,如外部类库未包含,实现代码未编写等. 但最终检查的结果,却是另外一种情况:文件名重名. ...