POJ 3544 Journey with Pigs

题意:有一个人有n头猪,他在从A镇到B镇的n个村庄中每个村庄卖一头猪,每个村庄猪的价格不同,有运费,问他最多能卖多少钱、

分析:很容易想到猪运的越远所花路费越多,因此每个村庄猪的实际售价实质等于猪的收购价-从A镇运到该镇的路费。

首先算出每个村庄的实际售价,剩下的就是匹配问题,当然猪的重量与村庄的实际售价成正比赚钱越多。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) a < b ? a : b
#define Max(a, b) a < b ? b : a
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
const double pi = acos(-1.0);
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 1000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int ans[MAXN];
struct P1
{
    int id;
    ll w;
    bool operator < (const P1 & a)const
    {
        return w > a.w;
    }
} num1[MAXN];
struct P2
{
    int id;
    ll d, p, real;
    bool operator < (const P2 & a)const
    {
        return real > a.real;
    }
} num2[MAXN];
int main()
{
    int n;
    ll t;
    while(scanf("%lld%lld", &n, &t) == 2)
    {
        for(int i = 0; i < n; ++i)
        {
            scanf("%lld", &num1[i].w);
            num1[i].id = i + 1;
        }
        for(int i = 0; i < n; ++i)
            scanf("%lld", &num2[i].d);
        for(int i = 0; i < n; ++i)
        {
            num2[i].id = i + 1;
            scanf("%lld", &num2[i].p);
            num2[i].real = num2[i].p - num2[i].d * t;
        }
        sort(num1, num1 + n);
        sort(num2, num2 + n);
        for(int i = 0; i < n; ++i)
        {
            ans[num2[i].id] = num1[i].id;
        }
        for(int i = 1; i <= n; ++i)
        {
            if(i > 1) printf(" ");
            printf("%d", ans[i]);
        }
        printf("\n");
    }
    return 0;
}
时间: 2024-09-29 00:04:38

POJ 3544 Journey with Pigs的相关文章

POJ3544 Journey with Pigs 动规基础贪心思想

非常经典的贪心题目,没有严格证明的话,肯定是YY着做的,题意: 约翰要从A到B,途中会经过N个村庄,他会带N只猪,然后卖掉,每个村庄卖一只,第i个村庄的人出价pi 每斤,从A到第i个存在的距离为disi,而且运一只猪需要话花费t * disi每斤,t一开始会给定 输入第一行n,t 接下来第一行 n个数,代表各个猪的重量 在接下来第二行n个数,代表每个村庄距离A的距离dis 在接下来第三行n个数,代表每个村庄出价p 输出n个数,表示每个村庄买的哪只猪 这题目一开始看到就往dp方向去想,但是发现不行

Problem J. Journey with Pigs

Problem J. Journey with Pigshttp://codeforces.com/gym/241680/problem/J考察排序不等式算出来单位重量在每个村庄的收益,然后生序排列猪的重量也生序排列此时价值最大 1 #include<iostream> 2 #include<cstdio> 3 #include<queue> 4 #include<algorithm> 5 #include<cmath> 6 #include&l

POJ 1149 PIGS(最大流)

POJ 1149 PIGS 题目链接 题意:有n个猪圈,m个顾客,猪圈中一开始有一些猪,顾客轮流来(注意是有先后顺序的),然后每个顾客会开启一些猪圈,在开启的猪圈中最多买b只猪,之后可以任意把剩下的猪分配到开着的猪圈中,问最多能卖出几只猪 思路:这题的关键在于建模,由于顾客有先后顺序,假如后来的顾客会开启x门,前面一个顾客也会开启x门,那么前面顾客相当与可以分配给后面顾客, 所以建模的方式为,源点和每个猪圈连,容量为猪圈猪数,每个猪圈和第一个开的顾客连,如果后面有顾客会开这个猪圈,则和之前的顾客

POJ 2488 A Knight&#39;s Journey

A Knight's Journey Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 248864-bit integer IO format: %lld      Java class name: Main Background  The knight is getting bored of seeing the same black and white squa

POJ 1149 PIGS 最大流

第一次做网络流,看着教材里面的题解做的= = 用的是Ford,应该是最好理解的把,就是不断的找有没有从源点到汇点的增广路然后更新. 建图真是难啊,而且感觉细节要注意的地方比较多,一开始没有考虑反向弧,WA了两发,sad... #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits> #include <strin

POJ 1149 PIGS(Dinic最大流)

PIGS Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20738   Accepted: 9481 Description Mirko works on a pig farm that consists of M locked pig-houses and Mirko can't unlock any pighouse because he doesn't have the keys. Customers come t

POJ 1149 PIGS (网络最大流 Dinic 建对图你就赢了)

PIGS Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17598   Accepted: 7977 Description Mirko works on a pig farm that consists of M locked pig-houses and Mirko can't unlock any pighouse because he doesn't have the keys. Customers come t

dfs/poj 2488 A Knight&#39;s Journey

1 #include<cstdio> 2 using namespace std; 3 const int b[8][2]={{-2,-1},{-2,1},{-1,-2},{-1,2},{1,-2},{1,2},{2,-1},{2,1}}; 4 int a[30][30],p,q; 5 struct 6 { 7 int x,y; 8 }step[910]; 9 10 bool dfs(int x,int y,int now) 11 { 12 if (now==p*q) return true;

POJ 1149 PIGS 迈克卖猪问题 网络流构图+三种AC方法

题目链接:POJ 1149 PIGS PIGS Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16533   Accepted: 7403 Description Mirko works on a pig farm that consists of M locked pig-houses and Mirko can't unlock any pighouse because he doesn't have the key