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. 洛谷T8115 毁灭

    题目描述 YJC决定对入侵C国的W国军队发动毁灭性打击.将C国看成一个平面直角坐标系,W国一共有n^2个人进入了C国境内,在每一个(x,y)(1≤x,y≤n)上都有恰好一个W国人.YJC决定使用m颗核 ...

  2. 在Framework2.0环境下运行3.5的代码

    因为许多的服务器特别是廉价的服务器上使用的是Framework的v2.0.50727.再加上自己开发的算是产品,所以就需要降低一些客户的前期成本,而自己同时也喜欢简单的代码.后来查了下,得知其实Fra ...

  3. 组合数问题(NOIP2016)

    原题传送门 这题啊. 裸的杨辉三角. 预处理杨辉三角和答案即可 下面贴代码 #include<iostream> #include<cstdio> #include<al ...

  4. SQL的四种连接查询(转)

    原文转自 https://blog.csdn.net/wangjingna/article/details/48765931

  5. unicode ascii 互转 函数 C实现 MultiByteToWideChar/WideCharToMultiByte 详解

    void Ascii2UnicodeLen(char*src,int len,unsigned short*tar) { unsigned int word_cnt; word_cnt=MultiBy ...

  6. Linux内核内存管理-内存访问与缺页中断【转】

    转自:https://yq.aliyun.com/articles/5865 摘要: 简单描述了x86 32位体系结构下Linux内核的用户进程和内核线程的线性地址空间和物理内存的联系,分析了高端内存 ...

  7. "select一直返回0"的问题解决和总结

    场景:一个简单的TCP 服务器,以实现UPNP的事件体系结构 我在linux平台下,创建一个TCP套接字,绑定到49156端口,向UPNP SERVER发一个subscribe订阅请求,超时时间设置为 ...

  8. Centos 6.3Yum安装NodeJS

    1. 添加epel源: (1)查看机器位数 file /sbin/init 或者 file /bin/ls (2)X64: rpm -ivh http://download.fedoraproject ...

  9. flask框架基本使用(1)(基本框架搭建与请求参数接收)

    #转载请留言联系 Flask 是一个 Python 实现的 Web 开发微框架. 1.搭建Flask开发环境 在你开发项目的时候,你拥有的项目越多,同时使用不同版本的 Python 工作的可能性也就越 ...

  10. JDK7集合框架源码阅读(一) ArrayList

    基于版本jdk1.7.0_80 java.util.ArrayList 代码如下 /* * Copyright (c) 1997, 2013, Oracle and/or its affiliates ...