题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=448

典型的最大子段和问题。

#include<iostream>
using namespace std;
int main()
{
int testNumber; //测试的数目
cin>>testNumber; for(int index=1;index<=testNumber;index++) //循环测试每组数据
{
int max=0,sum=0,tempNumber=0;
int tempStart=0;
int start=0,end=0; int number;
cin>>number;
for(int i=0;i<number-1;i++)
{
cin>>tempNumber;
sum+=tempNumber;
if(sum<0) //小于0的话暂时放弃之前的值,将下一个值作为起点
{
tempStart=i+1;
sum=0;
}
if(sum>max||(sum==max&&start==tempStart))//只有在大于最大值的时候才会更新
{
//一定要注意第二种情况,
//If more than one segment is maximally nice,
// choose the one with the longest cycle ride (largest j-i).
//To break ties in longest maximal segments,
//choose the segment that begins with the earliest stop (lowest i)
max=sum;
start=tempStart;
end=i;
}
}
if(max==0)
cout<<"Route "<<index<<" has no nice parts"<<endl;
else
cout<<"The nicest part of route "<<index<<" is between stops "<<start+1<<" and "<<end+2<<endl;
}
return 0;
}

UVA507-- Jill Rides Again的更多相关文章

  1. uva507 - Jill Rides Again(最长连续和)

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=448">题目:uva507 - Jill ...

  2. UVA 507 - Jill Rides Again 动态规划

      Jill Rides Again  Jill likes to ride her bicycle, but since the pretty city of Greenhills where sh ...

  3. UVa 507 - Jill Rides Again

    题目大意:最大和子序列问题.由于具有最大和的子序列具有一下性质:第一项不为负数,并且从第一项开始累加,中间不会有和出现负数,因为一旦有负数我们可以抛弃前边的部分以得到更大的子序列和,这将会产生矛盾. ...

  4. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  5. <算法竞赛入门经典> 第8章 贪心+递归+分治总结

    虽然都是算法基础,不过做了之后还是感觉有长进的,前期基础不打好后面学得很艰难的,现在才慢慢明白这个道理. 闲话少说,上VOJ上的专题训练吧:http://acm.hust.edu.cn/vjudge/ ...

  6. soj 1015 Jill's Tour Paths 解题报告

    题目描述: 1015. Jill's Tour Paths Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Every ...

  7. 常用rides命令

    rides使用步骤 1.源代码构建安装 1.下载,Linux下命令wget http://redis.io/download下载redis的包 2.解归档Linux下命令tar -xvf redis- ...

  8. uva-507

    题意:连续序列和最大,直接枚举..... 代码跑了2.4s.QAQ #include <string> #include<iostream> #include<map&g ...

  9. 分布式 +rides

    redis分布式部署 1.scrapy框架是否可以自己实现分布式? - 不可以.原因有二. 其一:因为多台机器上部署的scrapy会各自拥有各自的调度器,这样就使得多台机器无法分配start_urls ...

随机推荐

  1. Linux03--文件打包与解压

    参考了<鸟哥的Linux私房菜> 1.压缩命令 gzip(压缩)与zcat(解压并读出来) gzip 可以说是应用度最广的压缩命令了!目前 gzip 可以解开 compress, zip ...

  2. Android - Ant自动编译打包android项目 -- 1(转)

    1.  背景: Eclipse用起来虽然方便,但是编译打包android项目还是比较慢,尤其当要将应用打包发布到各个渠道时,用Eclipse手动打包各种渠道包就有点不切实际了,这时候我们用到Ant帮我 ...

  3. 凯恩斯主义VS货币主义

    Milton Friedman在1960年代后期以及整个1970年代,到处不知疲倦地像传教士一般地宣讲他的货币主义.当时,美联储成员几乎清一色地是凯恩斯主义者.你可以想像Friedman的对手是多么强 ...

  4. docker网络-如何让外部网络访问容器资源

    docker网络-如何让外部网络访问容器资源 安装httpd 服务: docker:/root# docker exec -it f63b2633d146 bash bash-4.1# yum ins ...

  5. 迎接 Windows Azure 和 DNN 挑战,几分钟内快速构建网站!

    编辑人员注释:本文章由高级商务策划师兼开发平台推广者 Neeti Gupta 撰写. 曾几何时,构建一个简单的网站需要耗费好几个月的时间.在过去,.NET 开发人员和设计社区的一些成员使用 DNN(以 ...

  6. static wechat red package tool

    ---------------------------------------------------------------------------------------------------- ...

  7. ceph理论及部署配置实践

    prefaces: ceph installation(quick)1,preflight(ins ceph-deploy repo tools)2,ceph storage cluster quic ...

  8. Subsequence(暴力+二分)

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10875   Accepted: 4493 Desc ...

  9. hdu4740【杭州网赛、模拟、有点搜索?】

    当时看了这题就感觉so easy...  本来不想写的,后来感觉是不是可以练一下搜索水平.. 比赛时有人过了就没写.       比赛完了写一下. 实现还不是那么顺利,  囧 本来自己以为这题能练下搜 ...

  10. 如果nginx 中worker_connections 值设置是1024,worker_processes 值设置是4,按反向代理模式下最大连接数的理论计算公式: 最大连接数 = worker_processes * worker_connections/4

    如果nginx 中worker_connections 值设置是1024,worker_processes 值设置是4,按反向代理模式下最大连接数的理论计算公式: 最大连接数 = worker_pro ...