Journey with Pigs
http://poj.org/problem?id=3544
Time limit:1000ms
Memory limit:65536k
Description
Farmer John has a pig farm near town a. He wants to visit his friend living in town B. During This journey the he would visit N small villages so he decided to earn. He tooks n Pigs and plans to sell one pig, and village he visits.
Pork prices in villages are different, in the J.-th Village The people would buy a pork at pJ Ru Bles 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 all town in order to earn as much as the possible.
Input
The "a" 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)-th E 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 1
50 70 60
Sample Output
3 2 1
Source
Northeastern Europe 2007, Northern subregion
Train of thought: first, according to the distance from a village and the cost of a unit journey, as well as the price of local pork, we can arrive at each village to sell pig unit weight of money to make out. Then, in descending order of earnings, the weight of the pig is sorted in descending order, and the maximum profit can be achieved by sorting inequalities.
Wikipedia--Sort inequalities
Complete code:
01./*32ms,216kb*/02.
#include <cstdio> #include <algorithm> 05.using namespace std;
06.typedef Long Long ll; 08.struct Node 09.
{ll value;
int position; BOOL operator < (const Node a) const 13.
{. return value > A.value; 15.} 16.}
WEIGHT[1010], earn[1010];
18.ll dis[1010];
19.int ans[1010]; 21.int main (void) 22.
{%. int n; ll t;///unit Freight 25. while (~SCANF ("%d%lld", &n, &t)) 26. {A for (int i = 1; I <= n; i++) 28.
{scanf ("%lld", &weight[i].value);
Weight[i].position = i; 31.} 32. for (int i = 1; I <= n; i++) 33.
scanf ("%lld", &dis[i]); for (int i = 1; I <= n; i++) 35.
{ll x;
scanf ("%lld", &x);
Earn[i].value = x-dis[i] * t; Earn[i].position = I 40.} 41.
Sort (weight + 1, weight + 1 + N);
A. Sort (earn + 1, earn + 1 + N); for (int i = 1; I <= N; i++) 44.
Ans[earn[i].position] = weight[i].position; for (int i = 1; i < n; i++) 46.
printf ("%d", ans[i]);
printf ("%d\n", Ans[n]); 48.} 49.
return 0; .}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/