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的更多相关文章

  1. poj 2769 感觉♂良好 (单调栈)

    poj 2769 感觉♂良好 (单调栈) 比尔正在研发一种关于人类情感的新数学理论.他最近致力于研究一个日子的好坏,如何影响人们对某个时期的回忆. 比尔为人的一天赋予了一个正整数值. 比尔称这个值为当 ...

  2. poj 2769 Reduced ID Numbers 同余定理

    链接:http://poj.org/problem?id=2769 题意:寻找数m,是的对于n个数的余数不同 思路:暴力,优化:同余部分不用测试 代码: #include <iostream&g ...

  3. poj 2769 Reduced ID Numbers(memset使用技巧)

    Description T. Chur teaches various groups of students at university U. Every U-student has a unique ...

  4. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  5. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  6. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  7. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  8. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  9. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

随机推荐

  1. Web启动服务器上的某一个服务

    情景是这样的.. 网页打开一个数据列表..数据要求实时从其他多个平台上获取.. 所以就有了一个Web页面..还有个WinService的服务来定时获取这些数据... 问题来了.. 发现Service有 ...

  2. CSS立体标签实现

    <style> .tag { background-color: #de3f33; position: relative; text-align: center; color: #fff; ...

  3. post、get的区别

    get的参数会显示在浏览器地址栏中,而 post的参数不会显示在浏览器地址栏中: 使用 post提交的页面在点击[刷新]按钮的时候浏览器一般会提示“是否重新提交”,而 get则不会: 用get的页面可 ...

  4. recording just for inquiry in the future

    auditd审计 相关命令有: auditd, auditctl, ausearch, aureport 相关文件: /etc/audit/auditd.conf, /etc/audit/audit. ...

  5. linux访问windows共享文件夹的方法

    博客转自:http://www.01happy.com/linux-access-windows-shares-folders/ 有时需要在linux下需要访问windows的共享文件夹,可以使用mo ...

  6. PostgreSQL中的时间操作总结

    取当前日期的函数: (1)       取当前时间:select now() (2)       取当前时间的日期: select current_date (3)       取当前具体时间(不含日 ...

  7. [Storm] java.io.FileNotFoundException: File '../stormconf.ser' does not exist

    This bug will kill supervisors Affects Version/s: 0.9.2-incubating, 0.9.3, 0.9.4 Fix Version/s: 0.10 ...

  8. No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing

    在Java中,类中的静态方法不能直接调用动态方法.只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法.所以在不做其他变动的情况下,最简单的解决办法是将public clas ...

  9. html 框架

    通过使用框架,你可以在同一个浏览器窗口中显示不止一个页面. 本例演示:如何使用三份不同的文档制作一个垂直框架. <html> <frameset cols="25%,50% ...

  10. 修改dedecms默认文章来源 "未知"改为关键词

    在dedecms后台发表文章时文章来源是可选的,有时我们没有选择或没填写,那么前台默认文章来源即“未知”.如何将dedecms默认文章来源改为自己想要的关键词呢?即将“未知”改为“keyword”呢? ...