题目链接: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. SQL字符型字段按数字型字段排序实现方法(转)

    由于是按字母顺序排列,所以123排在了2的前面,显然不符合我们的要求,那么怎样才能按照我们预想的数字顺序排序呢 ORDER BY `meta_value`   那么按得分排序得到的结果可能是:1101 ...

  2. Python下的机器学习工具sklearn--数据预处理

    1.数据标准化(Standardization or Mean Removal and Variance Scaling) 进行标准化缩放的数据均值为0,具有单位方差. from sklearn im ...

  3. cocos2d-x中常见的场景切换

    本文转载自:http://www.cnblogs.com/linux-ios/archive/2013/04/09/3010779.html bool HelloWorld::init() { /// ...

  4. python学习day2(一)

    一.上周作业回顾 1.登陆接口: 思路流程: 1.登陆,三次锁定用户 2.用户信息文件,黑名单文件 3.检测黑名单,如输入账号在黑名单中存在,不允许登陆 4.用户密码判断 主要知识点:while,fo ...

  5. ERS卫星

    http://www.esa.int/Our_Activities/Operations/ERS-2 ERS-2 ROLE Earth observation (EO) LAUNCH DATE 21 ...

  6. Mono For Android中简单实现按钮的动画效果

    Android中动画的分Tween Animation和Frame Animation,本节主要讲Tween Animation的实现. 一般是通过XML文件来定义动画的,具体如下: 1.在项目res ...

  7. 忘记linux密码

    http://blog.163.com/xygzlyq@126/blog/static/22585899200810471512530/

  8. 取PE文件的引入表和导出表

    直接上代码(这里列出C++和Delphi的代码),Delphi代码中包含导入及导出文件和函数列表,PE结构可参阅资料,很多很详细,需要注意的是,本例中是映射到内存,不是通过PE装载器装入的,所以对于节 ...

  9. rhel6.4 配置本地yum的源

    1 创建rhel-debuginfo.repo,如果有则先备份再删除       cd  /etc/yum.repos.d    rm  rhel-debuginfo.repo    vi  rhel ...

  10. poj3006

                                                                                 Dirichlet's Theorem on ...