uva507 - Jill Rides Again(最长连续和)
option=com_onlinejudge&Itemid=8&page=show_problem&problem=448">题目:uva507 - Jill Rides Again(最长连续和)
题目大意:给每两个站之间的惬意度,惬意的路线必须加起来的和不小于0.帮Jill找出她惬意的路线,要求是最长的,而且一样长的话取站相对靠前的。
代码:
#include <stdio.h>
#include <string.h> const int N = 20005;
int s, b, e;
int stop[N]; int solve () { int mm = stop[1];
int sum = stop[1];
int tems = 1;
b = e = 1; if (sum < 0) { tems = 2;
sum = 0;
} for (int i = 2; i < s; i++) { sum += stop[i];
if (sum < 0) { tems = i + 1;
sum = 0;
}
else if (sum >= mm) { if ( (sum == mm && i - tems > e - b) || sum > mm) { b = tems;
e = i;
mm = sum;
}
}
}
return mm;
} int main () { int t;
scanf ("%d", &t);
for (int i = 1; i <= t; i++) { scanf("%d", &s);
for (int j = 1; j < s; j++)
scanf ("%d", &stop[j]); int mm = solve();
if (mm < 0)
printf ("Route %d has no nice parts\n", i);
else
printf ("The nicest part of route %d is between stops %d and %d\n", i, b, e + 1);
}
return 0;
}
uva507 - Jill Rides Again(最长连续和)的更多相关文章
- UVA 507 - Jill Rides Again 动态规划
Jill Rides Again Jill likes to ride her bicycle, but since the pretty city of Greenhills where sh ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [LeetCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- Interview----最长连续乘积字串
题目描述: 给一个浮点数序列,取最大乘积连续子串的值,例如 -2.5,4,0,3,0.5,8,-1,则取出的最大乘积连续子串为3,0.5,8. 也就是说,上述数组中,3 0.5 8这3个数的乘积3*0 ...
- lintcode: 最长连续序列
最长连续序列 给定一个未排序的整数数组,找出最长连续序列的长度. 说明 要求你的算法复杂度为O(n) 样例 给出数组[100, 4, 200, 1, 3, 2],这个最长的连续序列是 [1, 2, 3 ...
- HDU 3308 线段树 最长连续上升子序列 单点更新 区间查询
题意: T个测试数据 n个数 q个查询 n个数 ( 下标从0开始) Q u v 查询 [u, v ] 区间最长连续上升子序列 U u v 把u位置改成v #include<iostream> ...
- poj3080Blue Jeans(在m个串中找到这m个串的 最长连续公共子序列)
Description The Genographic Project is a research partnership between IBM and The National Geographi ...
- LeetCode 674. Longest Continuous Increasing Subsequence (最长连续递增序列)
Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...
- LeetCode 485. Max Consecutive Ones (最长连续1)
Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...
随机推荐
- JS与jQuery中html-与-text方法的区别
所有的实例均用下面的html <div id="id0"> <div id="id1"> 直接text <p> <sp ...
- windows实时监测热插拔设备的变化2
//动态监测设备插拔 #include <Dbt.h> BEGIN_MESSAGE_MAP(ParticipateMeeting, CDialogEx) ON_WM_DEVICECHANG ...
- Linux USB驱动框架分析【转】
转自:http://blog.csdn.net/jeffade/article/details/7701431 Linux USB驱动框架分析(一) 初次接触和OS相关的设备驱动编写,感觉还挺有意思的 ...
- 使用MyQR生成二维码
from MyQR import myqr # 主要用到以下几个参数 # words:文本,可以是一个链接,或者你想说的话 # picture:你用到的图片,作为背景,不然只是一个光秃秃的二维码 # ...
- poj 3164(最小树形图模板)
题目链接:http://poj.org/problem?id=3164 详细可以看这里:http://www.cnblogs.com/vongang/archive/2012/07/18/259685 ...
- adb install 安卓apk的包
➜ ~ adb install /Users/jkr/Downloads/QYVideoClient-debug.apk /Users/jkr/Downloads/QYVideoClient-deb ...
- Peak
A sequence of \(n\) integers \(a_1, a_2, \dots, a_n\) is called a peak, if and only if there exists ...
- Python的功能模块[4] -> pdb/ipdb -> 实现 Python 的单步调试
pdb / ipdb 模块 / pdb / ipdb Module pdb 和 ipdb 的主要作用是用于 Python 程序的单步调试,Python 的调试可参考链接. 下面是一个简单的使用示例 i ...
- oracle wm_concat 拼接乱码 显示问号等
今天用plsql查询工具 拼接sql查询显示乱码,不知道为何. 后来经多方查找资料 现在分享如下. 针对oracle拼接函数的乱码,首先查询一下oracle字符的编码是否支持中文,查询语句: SELE ...
- Ubuntu 16.04 -- 同时配置Nginx(转发)和frp(内网映射)和HTTPS(ca加密) - 端口转发
Ubuntu16.04下: sudo apt -get nginx 用这条命令安装完nginx之后, nginx在该目录下: 然后配置nginx: 如下: 红圈圈住的地方多写几个可以做负载均衡. 端口 ...