ZOJ-3469 Food Delivery

在一个X坐标轴上,有n个顾客点了餐,要给他们送餐并让顾客们总厌烦值最小
顾客有x坐标和v厌烦度(每分钟增加v厌烦度),给出起始位置和自己的速度
首先这个速度是按照每走一单位需要V分钟给出的,所以总厌烦度记录为 已走距离*厌烦度,最后在乘以V
每次出发有两种选择,要么向左走到第一个没被送餐的顾客,或者向右走到第一个没被送餐的顾客
先把顾客按照从左到右的方向排好序,标号
用d[l][r][0]代表给l~r这个区间内的顾客都送餐后,并且最后处在l位置,所取得的最小厌烦度(包括区间内和区间外的)

d[l][r][1]就代表最后处在r位置的,sum[i]代表前i个人的v之和
if(k==0)
 {
  d[l][r][k]=min(d[l][r][k],dp(l+1,r,0)+(sum[l]+sum[n+1]-sum[r])*(a[l+1].x-a[l].x));
  d[l][r][k]=min(d[l][r][k],dp(l+1,r,1)+(sum[l]+sum[n+1]-sum[r])*(a[r].x-a[l].x));
 }
 else
 {
  d[l][r][k]=min(d[l][r][k],dp(l,r-1,0)+(sum[l-1]+sum[n+1]-sum[r-1])*(a[r].x-a[l].x));
  d[l][r][k]=min(d[l][r][k],dp(l,r-1,1)+(sum[l-1]+sum[n+1]-sum[r-1])*(a[r].x-a[r-1].x));
 }
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int N=1000+10;
const ll INF=1e18;
struct node
{
	ll x,v;
	bool operator < (const node &u) const
	{
		return x<u.x;
	}
}a[N];
ll d[N][N][2];
ll sum[N];
ll n,v0,x0;
ll dp(int l,int r,int k)
{
	if(l==r)
	{
		if(a[l].x==x0&&a[l].v==0) return 0;
		return INF;
	}
	if(d[l][r][k]!=-1) return d[l][r][k];
	d[l][r][k]=INF;
	if(k==0)
	{
		d[l][r][k]=min(d[l][r][k],dp(l+1,r,0)+(sum[l]+sum[n+1]-sum[r])*(a[l+1].x-a[l].x));
		d[l][r][k]=min(d[l][r][k],dp(l+1,r,1)+(sum[l]+sum[n+1]-sum[r])*(a[r].x-a[l].x));
	}
	else
	{
		d[l][r][k]=min(d[l][r][k],dp(l,r-1,0)+(sum[l-1]+sum[n+1]-sum[r-1])*(a[r].x-a[l].x));
		d[l][r][k]=min(d[l][r][k],dp(l,r-1,1)+(sum[l-1]+sum[n+1]-sum[r-1])*(a[r].x-a[r-1].x));
	}
	return d[l][r][k];
}
int main()
{
	while(~scanf("%lld%lld%lld",&n,&v0,&x0))
	{
		sum[0]=0;
		for(int i=1;i<=n;i++)
			scanf("%lld%lld",&a[i].x,&a[i].v);
		a[n+1].x=x0;a[n+1].v=0;
		sort(a+1,a+n+2);
		for(int i=1;i<=n+1;i++)
			sum[i]=sum[i-1]+a[i].v;
		memset(d,-1,sizeof(d));
		printf("%lld\n",min(dp(1,n+1,0),dp(1,n+1,1))*v0);
	}
    return 0 ;
}


Pizza delivery Pizza delivery

09-23

Problem DescriptionrnYour Irish pizza and kebab restaurant is doing very well. Not only is the restaurant full almost every night, but there is also an ever increasing number of deliveries to be made, all over town. To meet this demand, you realize that it will be necessary to separate the delivery service from the restaurant. A new large kitchen, only for baking pizzas and being a base for deliveries, has to be established somewhere in town. The main cost in the delivery service is not the making of the pizza itself, but the time it takes to deliver it. To minimize this, you need to carefully plan the location of the new kitchen. To your help you have a database of all last year's deliveries. For each block in the city, you know how many deliveries were made there last year. The kitchen location will be chosen based on the assumption that the pattern of demand will be the same in the future.rnYour city has a typical suburban layot – an orthogonal grid of equalsize square blocks. All places of interest (delivery points and the kitchen) are considered to be located at street crossings. The distance between two street crossings is the Manhattan distance, i.e., the number of blocks you have to drive vertically, plus the number of blocks you have to drive horizontally. The total cost for a delivery point is its Manhattan distance from the kitchen, times the number of deliveries to the point. Note that we are only counting the distance from the kitchen to the delivery point. rnEven though we always drive directly back to the kitchen after a delivery is made, this (equal) distance is not included in the cost measure.rn rnrnInputrnOn the rst line, there is a number, 1 <=n <=20, indicating the number ofrntest cases. Each test case begins with a line with two integers, 1 <= x <= 100, 1<= y <= 100, indicating the size of the two-dimenstional street grid. Then follow y lines, each with x integers, 0<= d <=1000, indicating the number of deliveries made to each street crossing last year.rn rnrnOutputrnFor each test case, output the least possible total delivery cost (the sum of all delivery costs last year), assuming that the kitchen was located optimally.There should be one line for each test case, with an integer indicating the cost, followed by a single space and the word 'blocks'.rn rnrnSample Inputrn2rn4 4rn0 8 2 0rn1 4 5 0rn0 1 0 1rn3 9 2 0rn6 7rn0 0 0 0 0 0rn0 1 0 3 0 1rn2 9 1 2 1 2rn8 7 1 3 4 3rn1 0 2 2 7 7rn0 1 0 0 1 0rn0 0 0 0 0 0rn rnrnSample Outputrn55 blocksrn162 blocks

Delivery

08-24

Karl is an impatient guy. He always wants to find the fastest way to solve any problem. As a delivery man, it's a very good personality because he can make the work more efficient.nnNow, Karl gets T tasks from his boss, which requires him to send the goods from cities to cities. There are N cities , numbered from 1 to N. And N-1 directional roads connect these cities. The ith road connects City i to City i+1 with a length Di. Moreover, there are M small Paths connect cities. They are also directional, and each of them has a length Qi. People can go through both roads and paths.nnKarl wants to find the shortest way to complete every task. But he is afraid to walk on the small path. So, in every task, he can only pass through at most 1 small path. He gets a little faint about this question, so he asked for your help.nnInputnnThere are few test cases. NOTICE that's no empty line between each test case. For each test case:nThe first line contains two integers N , M(1 <= N <= 100000 , 1 <= M <= 200000), indicating there are N cities and M small paths.nThe second line contains N-1 integers, indicating the length Di(1 <= Di <= 100000) of the ith directional road, which connects City i to City i+1.nThe following M lines indicates M small paths. Each line contains 3 integers Ai , Bi , Qi, (1 <= Ai <= N , 1 <= Bi <= N , 1 <= Qi <= 100000)indicating this directional small path connects City Ai to City Bi with length Qi.nThe next line contains a integer T(1 <= 200000), which means there are T tasks.nThe following T lines indicates the T tasks. Each line contains 2 integers Ui(1 <= Ui <= N) , Vi(1 <= Vi <= N), indicating you are asked to find the shortest way from City Ui to City Vi with the requirements. nWe promise that there is an answer to each Task.(There should be at least one way from City Ui to City Vi with requirements)nOutputnnFor each test case, for every task, output a integer in a line which shows the shortest way for the query with requirements.nWe promise that each answer will not exceed 2^31 - 1.nnSample Inputnn5 3n1 2 3 4n2 4 2n1 3 2n5 1 3n5n1 4n4 2n3 1n1 3n1 5nSample Outputnn3n8n10n2n7

Pizza delivery Pizza delivery Pizza delivery

09-23

Problem DescriptionrnYour Irish pizza and kebab restaurant is doing very well. Not only is the restaurant full almost every night, but there is also an ever increasing number of deliveries to be made, all over town. To meet this demand, you realize that it will be necessary to separate the delivery service from the restaurant. A new large kitchen, only for baking pizzas and being a base for deliveries, has to be established somewhere in town. The main cost in the delivery service is not the making of the pizza itself, but the time it takes to deliver it. To minimize this, you need to carefully plan the location of the new kitchen. To your help you have a database of all last year's deliveries. For each block in the city, you know how many deliveries were made there last year. The kitchen location will be chosen based on the assumption that the pattern of demand will be the same in the future.rnYour city has a typical suburban layot – an orthogonal grid of equalsize square blocks. All places of interest (delivery points and the kitchen) are considered to be located at street crossings. The distance between two street crossings is the Manhattan distance, i.e., the number of blocks you have to drive vertically, plus the number of blocks you have to drive horizontally. The total cost for a delivery point is its Manhattan distance from the kitchen, times the number of deliveries to the point. Note that we are only counting the distance from the kitchen to the delivery point. rnEven though we always drive directly back to the kitchen after a delivery is made, this (equal) distance is not included in the cost measure.rn rnrnInputrnOn the rst line, there is a number, 1 <=n <=20, indicating the number ofrntest cases. Each test case begins with a line with two integers, 1 <= x <= 100, 1<= y <= 100, indicating the size of the two-dimenstional street grid. Then follow y lines, each with x integers, 0<= d <=1000, indicating the number of deliveries made to each street crossing last year.rn rnrnOutputrnFor each test case, output the least possible total delivery cost (the sum of all delivery costs last year), assuming that the kitchen was located optimally.There should be one line for each test case, with an integer indicating the cost, followed by a single space and the word 'blocks'.rn rnrnSample Inputrn2rn4 4rn0 8 2 0rn1 4 5 0rn0 1 0 1rn3 9 2 0rn6 7rn0 0 0 0 0 0rn0 1 0 3 0 1rn2 9 1 2 1 2rn8 7 1 3 4 3rn1 0 2 2 7 7rn0 1 0 0 1 0rn0 0 0 0 0 0rn rnrnSample Outputrn55 blocksrn162 blocks

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试