codevs 1507 酒厂选址 题解报告

24 篇文章 0 订阅
8 篇文章 0 订阅


题目描述 Description

Abstinence(戒酒)岛的居民们酷爱一种无酒精啤酒。以前这种啤酒都是从波兰进口,但今年居民们想建一个自己的啤酒厂。岛上所有的城市都坐落在海边,并且由一条沿海岸线的环岛高速路连接。酒厂的投资者收集了关于啤酒需求量的信息,即每天各城市消费的啤酒桶数。另外还知道相邻城市之间的距离。每桶啤酒每英里的运费是1元。日运费是将所需要的啤酒从酒厂运到所有城市所必需的运费之和。日运费的多少和酒厂的选址有关。投资者想找到一个合适的城市来修建酒厂,以使得日运费最小。

请设计一个程序:从文件bre.in 读入城市的数目、相邻两城市间的距离以及每个城市消费的啤酒桶数,计算最小的日运费,将结果写到输出文件bre.out中。

输入描述 Input Description

第一行是一个整数n(5 <= n <= 10000) ,表示城市的数目。 城市沿高速路编号,使得相邻的城市的编号也相邻(城市1和n也被认为是相邻)。 以下的n行,每行有两个非负整数。第I+1行的数 zi、di分别是城市I每日的啤酒消费量(桶)和从城市I沿高速路到下一个城市的距离(英里)。高速路的总长不会超过65535 英里。每座城市的日消费量不会超过255桶。

输出描述 Output Description

一个整数,表示所需的最小日运费(元)。

样例输入 Sample Input

6

1 2

2 3

1 2

5 2

1 10

2 3

样例输出 Sample Output

41

数据范围及提示 Data Size & Hint


嗯,

不知道栋栋为啥超时系列/

表示栋神犇能999MSac

我也是服;

不过。。


测试点#bro0.in 结果: 内存使用量: 256kB 时间使用量: 0ms 
测试点#bro1.in 结果: 内存使用量: 256kB 时间使用量: 0ms 
测试点#bro10.in 结果: 内存使用量: 488kB 时间使用量: 88ms 
测试点#bro11.in 结果: 内存使用量: 488kB 时间使用量: 152ms 
测试点#bro11a.in 结果: 内存使用量: 128kB 时间使用量: 1ms 
测试点#bro12.in 结果: 内存使用量: 492kB 时间使用量: 152ms 
测试点#bro1a.in 结果: 内存使用量: 256kB 时间使用量: 1ms 
测试点#bro2.in 结果: 内存使用量: 256kB 时间使用量: 1ms 
测试点#bro2a.in 结果: 内存使用量: 256kB 时间使用量: 0ms 
测试点#bro3.in 结果: 内存使用量: 256kB 时间使用量: 0ms 
测试点#bro3a.in 结果: 内存使用量: 256kB 时间使用量: 0ms 
测试点#bro4.in 结果: 内存使用量: 256kB 时间使用量: 0ms 
测试点#bro5.in 结果: 内存使用量: 256kB 时间使用量: 0ms 
测试点#bro6.in 结果: 内存使用量: 364kB 时间使用量: 12ms 
测试点#bro7.in 结果: 内存使用量: 364kB 时间使用量: 27ms 
测试点#bro8.in 结果: 内存使用量: 364kB 时间使用量: 39ms 
测试点#bro9.in 结果: 内存使用量: 492kB 时间使用量: 75ms 

23333

我只能说

泥萌这些辣鸡!!


咳咳。

回到正题

首先,对于这个环

开个二倍的数组就好了

之后

for循环枚举每一个城市

对于每个城市。

枚举其他N-1个城市

递推计算距离和/

对答案取min就好了


代码::


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdlib>
#include<string>
#include<bitset>
#include<iomanip>
#include<deque>
#define INF 1000000000
#define fi first
#define se second
#define N 100005
#define P 1000000007
#define debug(x) cerr<<#x<<"="<<x<<endl
#define MP(x,y) make_pair(x,y)
using namespace std;
int n,m,k;
long long z[30001],d[30001],c[30001];
inline long long get_num()
{
long long num = 0;
char c;
bool flag = false;
while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
if (c == '-') flag = true;
else num = c - '0';
while (isdigit(c = getchar()))
num = num * 10 + c - '0';
return (flag ? -1 : 1) * num;
}
int main()
{
	cin>>n; 
    for(long long i=1;i<=n;i++)
    {
    	long long q,w;
    	cin>>z[i]>>d[i];
    }
    for(long long i=1;i<=n;i++)
    {
    	z[i+n]=z[i];
    	d[n+i]=d[i];
    	k+=d[i];
    }
    long long ans=1147483647000000000;
    for(long long i=1;i<=n;i++)
	{
		long long l=d[i],s=0;
		for(long long j=i+1;j<=i+n-1;j++)
		{
			if(l<=k-l)
			{
				s+=l*z[j];
			l+=d[j];
			}else
			{
				s+=(k-l)*z[j];
			l+=d[j];
			}
		}
		ans=min(ans,s);
	} 
    cout<<ans;
}

噫~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值