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. [ CodeVS冲杯之路 ] P3143

     不充钱,你怎么AC? 题目:http://codevs.cn/problem/3143/ 大水题一道,只要会遍历,这里讲一下思路 先序遍历:先输出,然后左儿子,最后右儿子 中序遍历:先左儿子,再输出 ...

  2. 同余方程(NOIP2012)

    原题传送门 水~ 纯拓展欧几里得算法.. #include<iostream> #include<cstdio> #define ll long long using name ...

  3. 杭电oj2032、2040、2042、2054、2055

    2032  杨辉三角 #include <stdio.h> int main(){ ][],i,j,n; while(~scanf("%d",&n)){ ;i& ...

  4. vue-cli 3.0脚手架与vux的配合使用

    在最近的项目中,引用了vux,在可拓展性以及复用性,都算是比较优秀的框架了.但是美中不足的是对于vux在对于vue-cli3.0的跟进还没有同步 需要自己做下修改,同比 有赞的vant 以及 ivie ...

  5. Shiro自定义realm实现密码验证及登录、密码加密注册、修改密码的验证

    一:先从登录开始,直接看代码 @RequestMapping(value="dologin",method = {RequestMethod.GET, RequestMethod. ...

  6. 3.sql

    from odps import ODPS o = ODPS(access_id="LTASVb3aOF3ghjek", secret_access_key="FeUoz ...

  7. 关于CI框架加入sphinx官方API接口文件的时候,需要注意的问题

    从sphinx下载的官方文件sphinxapi.php中类名为class SphinxClient 加入到CI框架,放在system/libraries/下,由于需要遵从CI框架libraries类名 ...

  8. java使用BeanUtils封装file类型表单数据到一个对象中

    package com.cc.web.servlet; import java.io.FileOutputStream; import java.io.IOException; import java ...

  9. Django和SQLAlchemy区别

    译者注:本文首先介绍了什么是ORM,然后从多个方面对Python语言下的两个ORM库Django和SQLAlchemy进行比较,为ORM的选型提供了较为全面的指导建议.以下是译文. ORM是什么? 在 ...

  10. SRM 733 Div 1 爆零记

    开场写easy(有预感要FST) 然后medium就卡住了. 我只知道$n$个点的生成树个数是$n^{n-2}$ 接下来直接狗带…… $Problem 250pts$ 水题,直接枚举然后记录答案(我大 ...