xdoj-1010(区间问题)
1 扫描一遍不行扫描两遍呗
2 O(n)时间确定cd[i] 【max( a[k]-_min) _min是k+1~n的最小值。i<=k<=n】
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
const int N=1e5+;
int a[N]; int n;
int cd[N];
int main ()
{
int T; scanf ("%d",&T);
while (T--) {
scanf ("%d",&n);
for (int i=;i<=n;i++) scanf ("%d",&a[i]);
int x=a[n]; int ans=-0x3f3f3f3f;
for (int i=n-;i>=;i--) {
ans=max (ans,x-a[i]);
cd[i]=ans;
x=max (x,a[i]);
}
x=a[]; ans=-0x3f3f3f3f; int t=-0x3f3f3f3f;
for (int i=;i<=n-;i++) {
ans=max(ans,a[i]-x);
t=max (t,ans+cd[i+]);
x=min (x,a[i]);
}
printf("%d\n",t);
}
return ;
}
xdoj-1010(区间问题)的更多相关文章
- xdoj 1241--余神的rp机(区间dp)
xdoj 1241---余神的rp机 核
- 2018中国大学生程序设计竞赛 - 网络选拔赛 1010 YJJ's Salesman 【离散化+树状数组维护区间最大值】
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6447 YJJ's Salesman Time Limit: 4000/2000 MS (Java/O ...
- COJ 1010 WZJ的数据结构(十) 线段树区间操作
传送门:http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=1001 WZJ的数据结构(十) 难度级别:D: 运行时间限制:3000ms: ...
- hihoCoder 1080 : 更为复杂的买卖房屋姿势 线段树区间更新
#1080 : 更为复杂的买卖房屋姿势 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho都是游戏迷,“模拟都市”是他们非常喜欢的一个游戏,在这个游戏里面他们 ...
- PAT 解题报告 1010. Radix (25)
1010. Radix (25) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 11 ...
- UVaLive 6609 Meeting Room Arrangement (贪心,区间不相交)
题意:给定 n 个区间,让你选出最多的区间,使得每个区间不相交. 析:贪心题,贪心策略是按右端点排序,然后按着选即可. 代码如下: #pragma comment(linker, "/STA ...
- HDOJ -- 4632 区间DP
Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65535 K (Java/ ...
- UVALive 2519 Radar Installation 雷达扫描 区间选点问题
题意:在坐标轴中给出n个岛屿的坐标,以及雷达的扫描距离,要求在y=0线上放尽量少的雷达能够覆盖全部岛屿. 很明显的区间选点问题. 代码: /* * Author: illuz <iilluzen ...
- USACO2004 Open提交作业(区间DP)
Description 贝西在哞哞大学选修了C门课,她要把这些课的作业交给老师,然后去车站和同学们一 起回家.老师们在办公室里,办公室要等他们下课后才开,第i门课的办公室在Ti时刻后开放. 所有的办公 ...
- 修长城 (区间DP)
Time Limit: 1000 ms Memory Limit: 256 MB Description 大家都知道,长城在自然条件下会被侵蚀,因此,我们需要修复.现在是21世纪,修复长城的事情当 ...
随机推荐
- vsftp的安装与配置
1.安装 直接使用yum安装,如果没有网络在其他机器使用yum先离线下载即可,vsftpd一般就自己不需要装其他依赖包 rpm -qa|grep vsftpd #查看是否安装 yum install ...
- Windows服务手动关闭教程
Windows上关闭软件自启动,经常使用360等软件的开机加速功能去优化. 但有时候有些服务开机是启动的但在360中并没有找到那如何手动关闭这些服务的自启动呢? 下边以Autodesk Applica ...
- springboot aop 自定义注解方式实现一套完善的日志记录(完整源码)
https://www.cnblogs.com/wenjunwei/p/9639909.html https://blog.csdn.net/tyrant_800/article/details/78 ...
- FFmpeg点播慢的最终方案
转载: 音视频交流群 发的一个总结. 原作者 请查看相关博客作者 http://blog.51cto.com/fengyuzaitu/2061036 场景要求 项目要求点播速度是300到500毫秒 ...
- 给div添加锚点
<div class="col-xs-3" id="myScrollspy"> <ul class="nav nav-tabs na ...
- 遍历所有子物体中renderer(渲染器)中的material(材质)并改变其alpha值实现若隐若现的效果
using UnityEngine;using System.Collections;using UnityEngine.UI; public class CubeControl : MonoBeha ...
- Python3 线程/进程池 concurrent.futures
python3之concurrent.futures一个多线程多进程的直接对接模块,python3.2有线程池了 Python标准库为我们提供了threading和multiprocessing模块编 ...
- tomcat 服务器线程问题
http://blog.csdn.net/wtopps/article/details/71339295 http://blog.csdn.net/wtopps/article/details/713 ...
- CentOS7安装配置Amanda
参考: https://wenku.baidu.com/view/881e0c998e9951e79a892759.html yum -y install amanda* http://blog ...
- 解决org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cacheManager' is defined
在Spring配置文件中加入了支持注解,即<mvc:annotation-driven/> 重新启动服务器包 org.springframework.beans.factory.NoSuc ...