POJ 3544 Journey with Pigs (贪心&排序不等式)
来源:互联网 发布:如何成为淘宝供应商 编辑:程序博客网 时间:2024/05/24 05:34
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 numbersdj (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 110 20 1510 20 3050 70 60
Sample Output
3 2 1
Source
/*32ms,216KB*/#include <cstdio>#include <algorithm>using namespace std;typedef long long ll;struct Node{ll value;int position;bool operator < (const Node a) const{return value > a.value;}} weight[1010], earn[1010];ll dis[1010];int ans[1010];int main(void){int n;ll t;///单位运费while (~scanf("%d%lld", &n, &t)){for (int i = 1; i <= n; i++){scanf("%lld", &weight[i].value);weight[i].position = i;}for (int i = 1; i <= n; i++)scanf("%lld", &dis[i]);for (int i = 1; i <= n; i++){ll x;scanf("%lld", &x);earn[i].value = x - dis[i] * t;earn[i].position = i;}sort(weight + 1, weight + 1 + n);sort(earn + 1, earn + 1 + n);for (int i = 1; i <= n; i++)ans[earn[i].position] = weight[i].position;for (int i = 1; i < n; i++)printf("%d ", ans[i]);printf("%d\n", ans[n]);}return 0;}
- POJ 3544 Journey with Pigs 贪心 + 不等式排序
- POJ 3544 Journey with Pigs (贪心&排序不等式)
- POJ 3544 Journey with Pigs (贪心+排序不等式)
- POJ 3544 Journey with Pigs 贪心
- POJ 3544 贪心 Journey with Pigs
- 贪心-poj-3544-Journey with Pigs
- poj 3544 Journey with Pigs---贪心
- POJ 3544 Journey with Pigs(贪心)
- poj 3544 Journey with Pigs(简单的贪心)
- 经典的贪心算法 Journey with Pigs (POJ 3544)
- Poj 3544 Journey with Pigs
- POJ 3544 Journey with Pigs
- POJ 3544 Journey with Pigs 可能会
- POJ3544 Journey with Pigs 动规基础贪心思想
- PIGS POJ
- PIGS POJ
- PIGS POJ
- POJ 1328(排序+贪心)
- 数字时钟 (JavaScript ,JQuery)
- 回到顶端插件 - ScrollUp
- Oracle 获取当前日期及转换日期格式
- jquery hotspot图片焦点区域标记鼠标滑过提示
- 浅谈 Android 中的地图和定位
- POJ 3544 Journey with Pigs (贪心&排序不等式)
- 大话分页(补充)——Threadlocal封装offSet和pageSize简化分页工具类
- 《程序员的自我修养--链接、装载与库》读书笔记之基础篇
- jquery mobile 响应式布局样式引用方法
- DEDECMS v5.7 完美实现导航条下拉二级菜单
- 2013胡润IT富豪榜发布 马化腾成IT新首富
- ArcGIS10.1正式版全套下载、安装与破解(附ArcGIS10.1全套下载地址)
- python通过exifread模块获得图片exif信息
- python使用点操作符访问字典(dict)数据