UVA 507 Jill Rides Again

Source: Internet
Author: User

Original question:
Jill likes to ride hers bicycle, but since the pretty city of Greenhills where she lives have grown, Jill often uses the ex Cellent public bus system for part of her journey. She has a folding bicycle which she carries and she when she uses the bus for the first part of hers trip. When the bus reaches some pleasant part of the city, Jill gets off and rides her bicycle. She follows the bus route until she reaches her destination or she comes to a part of the city she does isn't like. In the latter event she'll board the bus to finish hers trip. Through years of experience, Jill has the rated each road on a integer scale of "niceness." Positive niceness values indicate roads Jill likes; Negative values is used for roads she does don't like. There is not zero values. Jill plans where to leave the bus and start bicycling, as well as where to stop bicycling and re-join the bus Sum of niceness values of the roads she bicycles on is maximized. This means that she'll sometimes cycle alOng A road She does not like, provided that it joins up and the other parts of hers journey involving roads she likes enough to Compensate. It May, is, and no part of the suitable, the route is, cycling so, Jill takes the bus for its entire route. Conversely, it may be, the the whole route was so nice Jill won't use the bus at all. Since There is many different bus routes, each with several stops at which Jill could leave or enter the bus, she feels t Hat a computer program could help she identify the best part-to-cycle for each bus route.
Input
The input file contains information on several bus routes. The first line of the file was a single integer
B representing the number of the route descriptions in the file. The identifier for each route (R) is the
Sequence number within the data file, 1≤r≤b. Each route description begins with the number of
Stops on the Route:an integer s, 2≤s≤20,000 on a line by itself. The number of stops is followed by s−1 lines, each line I (1≤i < s) is an integer n i representing Jill's assessmen T of the niceness of the road between the stops I and I + 1.
Output
For each of the route r in the input file, your program should identify the beginning bus stop I and the
Ending bus stop J that identify the segment of the route which yields the maximal sum of niceness,
m = n i + N i+1 + ... + n j−1. If more than one segment are maximally nice, choose the one with the
Longest cycle Ride (largest j−i). To broke ties in longest maximal segments, choose the segment that begins with the earliest stop (lowest i). For each route r in the input file, print a line in the form:the nicest part of the route R is between stops I and J however, If the maximal sum isn't positive, your program should print:route R have no nice parts
Sample Input
3
3
-1
6
10
4
-5
4
-3
4
4
-4
4
-5
4
-2
-3
-4
Sample Output
The nicest part of Route 1 is between stops 2 and 3
The nicest part of Route 2 is between stops 3 and 9
Route 3 have no nice parts
English:
This is really a lot of nonsense, is to find the largest sub-paragraph and, if there are multiple answers, then find together the number of the most and the smallest starting point.

#include <bits/stdc++.h> using namespace std;
int a[20005];
FStream in,out;
    int main () {Ios::sync_with_stdio (false);
    int n,c,s;
    In.open ("Data.txt");
    Out.open ("Answer.txt");
    cin>>c;
        for (int t=1;t<=c;t++) {int st=1,en=-1,stm=1;
        cin>>s;
        memset (A,0,sizeof (a));
        for (int i=1;i<s;i++) cin>>a[i];
        int max=-1,tmp=0;
            for (int i=1;i<s;i++) {if (tmp>=0) tmp+=a[i];
                else {tmp=a[i];
            Stm=i; } if (tmp>max| |
                tmp==max&&i-stm>en-st) {max=tmp;
                st=stm;
            En=i;
        }} if (max<=0) cout<< "Route" <<t<< "have no nice parts" <<endl; Else cout<< "The nicest part of the route" <<t<< "is between stops" &LT;&LT;ST&LT;&Lt; "and" <<en+1<<endl;
    if (t!=c)} in.close ();
    Out.close ();
return 0;
 }

Answer:
The maximum number of sub-paragraphs and, is almost a bare topic. Look for the start and end of the line ~

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.