博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[USACO08MAR]土地征用Land Acquisition
阅读量:5334 次
发布时间:2019-06-15

本文共 2449 字,大约阅读时间需要 8 分钟。

[USACO08MAR]土地征用Land Acquisition

题目描述

Farmer John is considering buying more land for the farm and has his eye on N (1 <= N <= 50,000) additional rectangular plots, each with integer dimensions (1 <= width_i <= 1,000,000; 1 <= length_i <= 1,000,000).

If FJ wants to buy a single piece of land, the cost is $1/square unit, but savings are available for large purchases. He can buy any number of plots of land for a price in dollars that is the width of the widest plot times the length of the longest plot. Of course, land plots cannot be rotated, i.e., if Farmer John buys a 3x5 plot and a 5x3 plot in a group, he will pay 5x5=25.

FJ wants to grow his farm as much as possible and desires all the plots of land. Being both clever and frugal, it dawns on him that he can purchase the land in successive groups, cleverly minimizing the total cost by grouping various plots that have advantageous width or length values.

Given the number of plots for sale and the dimensions of each, determine the minimum amount for which Farmer John can purchase all

 

输入输出格式

输入格式:

 

* Line 1: A single integer: N

* Lines 2..N+1: Line i+1 describes plot i with two space-separated integers: width_i and length_i

 

输出格式:

 

* Line 1: The minimum amount necessary to buy all the plots.

 

输入输出样例

输入样例#1: 
4 100 1 15 15 20 5 1 100
输出样例#1: 
500

说明

There are four plots for sale with dimensions as shown.

The first group contains a 100x1 plot and costs 100. The next group contains a 1x100 plot and costs 100. The last group contains both the 20x5 plot and the 15x15 plot and costs 300. The total cost is 500, which is minimal.

 

翻译:

约翰准备扩大他的农场,眼前他正在考虑购买N块长方形的土地。如果约翰单买一块土 地,价格就是土地的面积。但他可以选择并购一组土地,并购的价格为这些土地中最大的长 乘以最大的宽。比如约翰并购一块3 × 5和一块5 × 3的土地,他只需要支付5 × 5 = 25元, 比单买合算。 约翰希望买下所有的土地。他发现,将这些土地分成不同的小组来并购可以节省经费。 给定每份土地的尺寸,请你帮助他计算购买所有土地所需的最小费用。

思路:

首先,我们按照x排序,用单调队列维护出来没有任何一块土地的a[i].x<=a[j].x && a[i].y<=a[j].y,然后如果x按升序,那么y一定降序dp[i]=max(dp[j]+a[j+1].y*a[i].x); 斜率优化即可

 

#include
#include
#include
#include
#include
#define rep(i,a,b) for(long long i=a;i<=b;i++)#define MAXN 50005using namespace std;long long n,m,q[MAXN],l,r,dp[MAXN];deque
Q;struct zlk{ long long x,y;}a[MAXN],b[MAXN];bool cmpp(zlk t,zlk r){ if(t.x!=r.x) return t.x

 

  

 

转载于:https://www.cnblogs.com/handsome-zlk/p/10234847.html

你可能感兴趣的文章
对闭包的理解
查看>>
练习10-1 使用递归函数计算1到n之和(10 分
查看>>
Oracle MySQL yaSSL 不明细节缓冲区溢出漏洞2
查看>>
windows编程ASCII问题
查看>>
.net webService代理类
查看>>
Code Snippet
查看>>
Node.js Express项目搭建
查看>>
zoj 1232 Adventure of Super Mario
查看>>
1201 网页基础--JavaScript(DOM)
查看>>
组合数学 UVa 11538 Chess Queen
查看>>
oracle job
查看>>
Redis常用命令
查看>>
XML学习笔记(二)-- DTD格式规范
查看>>
IOS开发学习笔记026-UITableView的使用
查看>>
[转载]电脑小绝技
查看>>
windos系统定时执行批处理文件(bat文件)
查看>>
thinkphp如何实现伪静态
查看>>
BZOJ 2243: [SDOI2011]染色( 树链剖分 )
查看>>
BZOJ 1925: [Sdoi2010]地精部落( dp )
查看>>
c++中的string常用函数用法总结!
查看>>