1507 Winery Site Selection

Source: Internet
Author: User

1507 Winery Site Selection

time limit: 1 sspace limit: 128000 KBtitle level: Golden Gold SolvingView Run ResultsTitle Description Description

The residents of Abstinence Island are fond of a non-alcoholic beer. The beer used to be imported from Poland, but this year residents want to build their own brewery. All the cities on the island are located by the sea and are connected by a roundabout expressway along the coastline. The winery's investors collected information about the demand for beer, which is the number of beer barrels consumed in each city each day. Also know the distance between neighboring cities. The shipping cost per bucket of beer is 1 yuan per mile. Daily freight is the sum of the freight required to transport the required beer from the winery to all the cities. The amount of daily freight is related to the location of the winery. Investors want to find a suitable city to build a winery so that the daily freight is minimal.

Please design a program: Read the number of cities from the file bre.in, the distance between two adjacent cities, and the number of beer barrels consumed per city, calculate the minimum daily shipping cost, and write the results to the output file bre.out.

Enter a description Input Description

The first line is an integer n (5 <= n <= 10000) that represents the number of cities. The city is numbered along the highway, making the adjacent city numbers also adjacent (cities 1 and N are also considered adjacent). The following n rows have two non-negative integers per line. The number of i+1 lines Zi, di is the city I daily beer consumption (barrels) and from the city I along the highway to the next city distance (miles). The total length of the motorway will not exceed 65535 miles. Daily consumption in each city will not exceed 255 barrels.

Output description Output Description

An integer that represents the minimum daily freight (yuan) required.

Sample input Sample Input

6

1 2

2 3

1 2

5 2

1 10

2 3

Sample output Sample Output

41

Data range and Tips Data Size & HintCategory labels Tags Click here to expand

Code Listing 1:

#include <cstdio>#include<iostream>#include<algorithm>using namespacestd;ints[10100],v[10100],d[10100],n,sum;intMain () {CIN>>N;  for(intI=1; i<=n;i++) {cin>>v[i]>>D[i]; Sum+=D[i]; S[i]=s[i-1]+d[i-1]; }    intmaxx=0x3f3f3f3f;  for(intI=1; i<=n;i++){        intt=0;  for(intj=1; j<=n;j++){            if(I==J)Continue; intQ=abs (s[j]-S[i]); intDis=min (q,sum-q); T+=dis*V[j]; }        if(T<=maxx) maxx=T; } cout<<maxx<<Endl; return 0;}

Code Listing 2:

1507 Winery Site Selection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.