SRM 399 DIV2 [250]

TopCoder SRM 专栏收录该内容
11 篇文章 0 订阅
#include < iostream >
#include
< vector >
using   namespace  std;

class  CircularLine {
public:
    
int longestTravel(vector<int> t)
    
{
        
int len=t.size();
        
int longest=0;
        
for (int i=0;i!=len-1;++i)
            
for (int j=i+1;j!=len;++j){
                
int temp=0,min=0;
                
for (int k=i;k!=j;++k)
                    min
+=t[k];
                
for (int k=j;k%len!=i;++k)
                    temp
+=t[k%len];
                
if (temp<min) min=temp;
                
if (min>longest) longest=min;
            }

        
return longest;
    }

}
;

Problem Statement

    

There's a circular subway line that contains n stations numbered 0 through n-1. The time to travel between stations 0 and 1 is t[0], the time to travel between stations 1 and 2 is t[1], ..., the time to travel between stations n-1 and 0 is t[n-1]. You can travel between stations in either direction, so there are always two ways to get from one station to another without visiting the same station more than once. For example, if there are 4 stations, the two ways of getting from station 1 to station 3 are 1-2-3 and 1-0-3. The total travel time in the first case is t[1] + t[2], and in the second case, it is t[0] + t[3]. When a person needs to get from one station to another, she always chooses the faster of the two ways.

You are given a vector <int> t. Find two stations such that the fastest travel time between them is the maximal possible. Return this time.

Definition

    
Class: CircularLine
Method: longestTravel
Parameters: vector <int>
Returns: int
Method signature: int longestTravel(vector <int> t)
(be sure your method is public)
    
 

Constraints

- t will contain between 3 and 50 elements, inclusive.
- Each element of t will be between 1 and 1000, inclusive.

Examples

0)  
    
{1,1,1,1}
Returns: 2
 
1)  
    
{1,4,4,1,5}
Returns: 7
The longest travel time is between stations 1 and 3.
2)  
    
{1,1,1000}
Returns: 2
You must never travel from station 2 to station 0 using the 1000 segment.
3)  
    
{1,1000,1,1000}
Returns: 1001
 
4)  
    
{1,1,1,1,4}
Returns: 4
 

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值