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. 我对 aspnetpager和repeater以及查询条件的封装

    /// <summary>         /// 绑定所有图片列表         /// </summary>         /// <param name=&qu ...

  2. [hdu1695] GCD ——欧拉函数+容斥原理

    题目 给定两个区间[1, b], [1, d],统计数对的个数(x, y)满足: \(x \in [1, b]\), \(y \in [1, d]\) ; \(gcd(x, y) = k\) HDU1 ...

  3. bzoj 4765 普通计算姬 dfs序 + 分块

    题目链接 Description "奋战三星期,造台计算机".小G响应号召,花了三小时造了台普通计算姬.普通计算姬比普通计算机要厉害一些.普通计算机能计算数列区间和,而普通计算姬能 ...

  4. bind 简单配置dns

    一. 安装apt-get install bind9 apt-get install bind9-host dnsutils apt-get install bind9-doc 二.修改本机配置我们要 ...

  5. BeeUISignal详解

    https://github.com/i5ting/Bee_Tutorial/wiki/BeeUISignal%E8%AF%A6%E8%A7%A3 BeeUISignal是beeframework的核 ...

  6. java基础练习 17

    import java.util.Scanner; public class Seventheen { /*企业发放的奖金根据利润提成.利润(I)低于或等于10万元时,奖金可提10%:利润高于10万元 ...

  7. Scala学习随笔——深入类和对象

    函数化对象(又称方程化对象)指的是所定义的类或对象不包含任何可以修改的状态. 本篇随笔就是着重记录函数化对象.定义了一个有理数类定义的几个不同版本,以介绍 Scala 类定义的几个特性:类参数和构造函 ...

  8. Delphi中的堆,栈

    来自:http://blog.163.com/liang_liu99/blog/static/884152162009111303756371/ --------------------------- ...

  9. Centos7下zabbix部署(四)定义报警媒介-邮件

    1.安装发送邮件工具mailx [root@zabbix-server ~]# yum install mailx -y 2.自定义使用163邮箱为默认发件人(避免被当作垃圾邮件) set from= ...

  10. HDU 6166.Senior Pan()-最短路(Dijkstra添加超源点、超汇点)+二进制划分集合 (2017 Multi-University Training Contest - Team 9 1006)

    学长好久之前讲的,本来好久好久之前就要写题解的,一直都没写,懒死_(:з」∠)_ Senior Pan Time Limit: 12000/6000 MS (Java/Others)    Memor ...