UVA507-- Jill Rides Again
题目链接: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的更多相关文章
- uva507 - Jill Rides Again(最长连续和)
option=com_onlinejudge&Itemid=8&page=show_problem&problem=448">题目:uva507 - Jill ...
- UVA 507 - Jill Rides Again 动态规划
Jill Rides Again Jill likes to ride her bicycle, but since the pretty city of Greenhills where sh ...
- UVa 507 - Jill Rides Again
题目大意:最大和子序列问题.由于具有最大和的子序列具有一下性质:第一项不为负数,并且从第一项开始累加,中间不会有和出现负数,因为一旦有负数我们可以抛弃前边的部分以得到更大的子序列和,这将会产生矛盾. ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- <算法竞赛入门经典> 第8章 贪心+递归+分治总结
虽然都是算法基础,不过做了之后还是感觉有长进的,前期基础不打好后面学得很艰难的,现在才慢慢明白这个道理. 闲话少说,上VOJ上的专题训练吧:http://acm.hust.edu.cn/vjudge/ ...
- soj 1015 Jill's Tour Paths 解题报告
题目描述: 1015. Jill's Tour Paths Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Every ...
- 常用rides命令
rides使用步骤 1.源代码构建安装 1.下载,Linux下命令wget http://redis.io/download下载redis的包 2.解归档Linux下命令tar -xvf redis- ...
- uva-507
题意:连续序列和最大,直接枚举..... 代码跑了2.4s.QAQ #include <string> #include<iostream> #include<map&g ...
- 分布式 +rides
redis分布式部署 1.scrapy框架是否可以自己实现分布式? - 不可以.原因有二. 其一:因为多台机器上部署的scrapy会各自拥有各自的调度器,这样就使得多台机器无法分配start_urls ...
随机推荐
- 图解musk这个神人
- EditText 空指针问题
今天在Android中碰到了这样一个问题,其实应该很少人会碰到,因为只有像我这种奇葩才会犯这种错误. 但既然解决了,我就想在这里跟大家分享一下,毕竟它困扰了我一个白天啊...不多说了,看下面... 其 ...
- AWS之EC2远程登录
网上有丰富的免费资源,Amazon的云主机就是开发者和学习者很好的选择. 但你得有一张信用卡,注册个AWS(Amazon web service)账号,就可以有自己公网ip的服务器了!!! 最近在折腾 ...
- knockout computed实例
function Privilege(options) { var self = this; self.fieldId = options.fieldId; self.readAccessType = ...
- MYSQL 没有varchar(max)这个类型。
背景: MYSQL 中不可以用varchar(max) 这种类型列来建立表 -------------------------------------------------------------- ...
- jQuery学习-事件之绑定事件(六)
在jQuery中,为了屏蔽event对象在各浏览器中的差异性,它使用了自定的Event对象,如下: 1 jQuery.Event = function( src, props ) { 2 ...
- H面试程序(29):求最大递增数
要求:求最大递增数 如:1231123451 输出12345 #include<stdio.h> #include<assert.h> void find(char *s) { ...
- OpenStreetMap(OSM) for developers
This article from: http://wiki.openstreetmap.org/wiki/Develop OpenStreetMap isn't just open data - i ...
- 【PAT】1012. The Best Rank (25)
题目链接: http://pat.zju.edu.cn/contests/pat-a-practise/1012 题目描述: To evaluate the performance of our fi ...
- NBA工资帽
工资帽(Salary cap):在NBA,工资帽是最著名工资限制条款. 每年的"工资帽"是依据NBA前一年的总收入,然后取这个总收入的48%作为NBA球队工资总额. 再拿这48%的 ...