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(最长连续和)的更多相关文章

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

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

  2. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  3. [LeetCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  4. Interview----最长连续乘积字串

    题目描述: 给一个浮点数序列,取最大乘积连续子串的值,例如 -2.5,4,0,3,0.5,8,-1,则取出的最大乘积连续子串为3,0.5,8. 也就是说,上述数组中,3 0.5 8这3个数的乘积3*0 ...

  5. lintcode: 最长连续序列

    最长连续序列 给定一个未排序的整数数组,找出最长连续序列的长度. 说明 要求你的算法复杂度为O(n) 样例 给出数组[100, 4, 200, 1, 3, 2],这个最长的连续序列是 [1, 2, 3 ...

  6. HDU 3308 线段树 最长连续上升子序列 单点更新 区间查询

    题意: T个测试数据 n个数 q个查询 n个数 ( 下标从0开始) Q u v 查询 [u, v ] 区间最长连续上升子序列 U u v 把u位置改成v #include<iostream> ...

  7. poj3080Blue Jeans(在m个串中找到这m个串的 最长连续公共子序列)

    Description The Genographic Project is a research partnership between IBM and The National Geographi ...

  8. LeetCode 674. Longest Continuous Increasing Subsequence (最长连续递增序列)

    Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...

  9. LeetCode 485. Max Consecutive Ones (最长连续1)

    Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...

随机推荐

  1. Java笔记(一)

    1. ConcurrentModificationException 在遍历容器的同时修改容器里的成员对象可能会抛出该异常 http://www.blogjava.net/EvanLiu/archiv ...

  2. 求强连通块_Tarjan算法_C++

    好久没有写算法了,就放一个 Tarjan 上来凑凑数哈 强连通块由若干个点组成,任意点与点之间可以之间或间接到达,显然可以看作一个环 下面是伪代码 强记:dfn为时间不变,low取最小,下一个dfn有 ...

  3. iphone CGBitmapContextCreate()函数解释

    http://blog.sina.com.cn/s/blog_3e50cef401019cd2.html CGContextRef CGBitmapContextCreate ( void *data ...

  4. 9.OpenStack安装web界面

    安装仪表板 安装仪表板组件 yum install -y openstack-dashboard httpd mod_wsgi memcached python-memcached 编辑/etc/op ...

  5. JAVA快速功能

    1.日期格式化 Date date=new Date(); //转换成时间格式12小时制 SimpleDateFormat df_12=new SimpleDateFormat("yyyy- ...

  6. os.path.isfile的错误

    今天写了一个程序,读取子目录(source)下的所有文件,然后转换. 程序一部分代码如下: def DtoTab(dsrc, dtarget): try: for item in os.listdir ...

  7. 利用js将图片地址进行转义

    利用js将图片地址进行转义 在业务中经常需要将图片从后台获取,然后在前台显示.其中后台存取图片主要分为两种,一种是数据库中获取图片的地址,第二种是存取图片内容的信息.这次主要是前台代码处理第一种情况. ...

  8. HDU 1074 Doing Homework(状压DP)

    第一次写博客ORZ…… http://acm.split.hdu.edu.cn/showproblem.php?pid=1074 http://acm.hdu.edu.cn/showproblem.p ...

  9. Sql Jions 的简易理解

    Sql Jions 的简易理解 Select  * from TableA A  left jion TableB  B on  A.key = B.key Select  * from TableA ...

  10. Broken Code

    给一个sorted array 0 0 0 1 1 1 1,然后找出第一个1的位置. 边界情况:array为空或者全0. 思路:二分查找.为了优化,可以先判断最后一个数是不是0. class Solu ...