"NOIP2011 day2" Sightseeing bus _noip2011

Source: Internet
Author: User
Tags stdin
3. Sightseeing bus

(Bus.cpp/c/pas)
"Problem description"
The charming small city of Y City, has n a beautiful scenic spot. Because of the increasing number of visitors, Y City Special
Arranged a sightseeing bus, to provide more convenient transportation services for tourists. The sightseeing bus appears at 1 in the first 0 minutes.
Attractions, followed by the 2, 3, 4......N attractions. A Di minute is required to open from the No. I scenic spot to i+1.
At any moment, the bus can only drive forward, or wait at the scenic spot.
With a total of M visitors, each traveler needs to travel 1 times from one attraction to another, the first visitors to the
Ti minute comes to the attractions AI, hoping to travel to attractions Bi (Ai < Bi). To enable all passengers to reach their destinations smoothly,
National Information Science Olympic League (NOIP2011) to improve the group Day2
4th page Total 4 pages
The bus must wait at every stop. All the passengers who need to go from this point of view will be on the bus before they can set off for the next attraction.
Let's say passengers don't need time to ride up and down.
A passenger's travel time is equal to the moment when he arrives at his destination minus the moment when he arrives at the point of departure. Because there is only one
Sightseeing cars, sometimes stopping for other passengers, and passengers complaining about the long travel time. So the Wise division
The machine ZZ installed K-nitrogen Accelerator for buses, each using an accelerator, you can reduce one of the Di minus 1. For
The same di can use the accelerator repeatedly, but it must be guaranteed that DI is greater than or equal to 0.
So how should ZZ arrange to use accelerators to minimize the total travel time for all passengers?
Enter
The input file name is bus.in.
Line 1th is 3 integers n, m, K, separated by a single space for each of the two integers. Number of attractions, number of passengers
And the number of nitrogen accelerators.
Line 2nd is a n-1 integer, separated by a single space between two integers, and the number I indicates is opened from the first scenic spot
The time required to i+1 a scenic spot, that is, Di.
Line 3rd to m+2 3 integers per line Ti, Ai, Bi, separated by a single space for each of the two integers. I+2 Row Table
Show me the passengers arrive at the point of departure, the number of sights to set out and the sights to reach.
Output
The output file name is Bus.out. A row that contains an integer that represents the minimum total travel time.
"Input and Output sample"
Bus.in Bus.out
3 3 2
1 4
0 1 3
1 1 2
5 2 3
10
"Input and Output sample description"
Using 2 accelerators for D2, the time from 2nd attractions to 3rd scenic spots changed to 2 minutes.
The bus departs from 1th in the 1th minute, 2 minutes to 2nd, and the 5th minute departs from the No. 2nd scenic spot.
The first 7 minutes to reach the 3rd scenic spot.
The 1th traveler travel time 7-0 = 7 minutes.
The 2nd traveler travel Time 2-1 = 1 minutes.
The 3rd Traveler travel Time 7-5 = 2 minutes.
Total time 7+1+2 = 10 minutes.
"Data Range"
For 10% of the data, k=0;
For 20% of the data, k=1;
For 40% of the data, 2≤n≤50,1≤m≤1,000,0≤k≤20,0≤di≤10,0≤ti≤500;
For 60% of the data, 1≤n≤100,1≤m≤1,000,0≤k≤100,0≤di≤100,0≤ti≤10,000;
For 100% of the data, 1≤n≤1,000,1≤m≤10,000,0≤k≤100,000,0≤di≤100,
0≤ti≤100,000.

The first consideration is to put the nitrogen accelerator on more people, so what is the effect of using the nitrogen accelerator on a certain section of the road?
If the bus stops at the first station (Arr[i]<sta[i]), then the people who are in the car will be affected.
So for the use of every nitrogen accelerator, we can traverse each bus station from the back forward, statistical suffix (that is, the number of people affected), if you want to stay, then set it as a breakpoint, to add, find the most valuable section of the road after the use of nitrogen accelerator, and recalculate arrival and departure time.

#include <cstdio> #include <iostream> #include <cstring> #include <cmath> #include <

Algorithm> using namespace std;

#define MAXN 1000 #define MAXM 10000 #define INF 0x3f3f3f3f typedef long Long int LL;
int dist[maxn+10];
int arr[maxn+10],sta[maxn+10];
int out[maxn+10],man[maxn+10];
int n,m,k;

int ans=0;
    int main () {//freopen ("bus.in", "R", stdin);

    Freopen ("Bus.out", "w", stdout);
    scanf ("%d%d%d", &n,&m,&k);

    int i,j;

    for (I=1;i<n;++i) scanf ("%d", &dist[i]);
    int a,b,c;
        for (i=1;i<=m;++i) {scanf ("%d%d%d", &c,&a,&b);
        ++OUT[B];
        Sta[a]=max (STA[A],C);

        ans-=c;//, when you get out of here, all of you.} while (k--) {memset (Man,0,sizeof (Mans));

        for (i=2;i<=n;++i)//Let me see how long I'm here now Arr[i]=max (Arr[i-1],sta[i-1]) +dist[i-1];
                for (i=n;i>1;--i) {if (dist[i-1]) {man[i-1]=out[i]; IfArr[i]>sta[i] man[i-1]+=man[i];//Gee, don't wait, fly directly} else man[i-1]=0;//This path cannot be deleted,
        And then delete the maxval=0,times,pos=-1 int;
                for (I=1;i<n;++i) if (Maxval<man[i]) {maxval=man[i];
            Times= pos=i;
    if (pos==-1) break;//deleted, do not delete else--dist[pos];

    for (i=2;i<=n;++i)//Let me see how long I'm here now Arr[i]=max (Arr[i-1],sta[i-1]) +dist[i-1];

    for (I=1;i<=n;++i) ans+=arr[i]*out[i];

    printf ("%d\n", ans);
    Fclose (stdin);
Fclose (stdout); }/* 3 3 8 1 4 0 1 3 1 1 2 5 2 3 2 5 110 100 1 1 2 100 1 2 9 1 2 65 1 2 4 1 2 10 5 0 A-
 6 9 14 4 8 1 1 4 * *

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.