哈理工OJ 2116 Maximum continuous product(思维的体操)
来源:互联网 发布:sql server 2008免费版 编辑:程序博客网 时间:2024/06/05 17:21
Maximum continuous product
Time Limit: 1000 MS Memory Limit: 32768 K
Total Submit: 111(37 users) Total Accepted: 34(30 users) Rating: Special Judge: No
Description
Wind and his GF(game friend) are playing a small game. They use the computer to randomly generated a number sequence which only include number 2,0 and -2. To be the winner,wind must
have to find a continuous subsequence whose continuous product is maximum.
For example, we have a sequence blow:
2 2 0 -2 0 2 2 -2 -2 0
Among all of it’s continuous subsequences, 2 2 -2 -2 own the maximum continuous product.
(2*2*(-2)*(-2) = 16 ,and 16 is the maximum continuous product)
You,wind’s friend,can give him a hand.
Input
The first line is an integer T which is the Case number(T <= 200).
For each test case, there is an integer N indicating the length of the number sequence.(1<= N <= 10000)
The next line,there are N integers which only include 2,0 and -2.
Output
For each case,you have to output the case number first(Reference the sample).
If the answer is smaller than 0, you just need to output 0 as the answer.
If the answer’s format is 2^x,you need to output the x as the answer.
Output the answer in one line.
Sample Input
2
2
-2 0
10
2 2 0 -2 0 2 2 -2 -2 0
Sample Output
Case #1: 0
Case #2: 4
题目大意:给你一组数,这组数由0,-2,2组成。让你求出最大的连续积,然后输出它是2的多少次方,如果最大积为0 的话输出0。
思路:暴力扫。
下面是AC代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int a[10005];int main(){ int t,iCase=0; scanf("%d",&t); while(t--) { iCase++; int n; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&a[i]); } int maxn=0,cnt,flag; for(int i=0;i<n;i++) { if(a[i]==0) { continue; } cnt=0; flag=0; for(int j=i;j<n;j++) { if(a[j]==0) { break; } if(a[j]==2) { cnt++; } if(a[j]==-2) { flag=1-flag; cnt++; } if(flag==0) { maxn=max(maxn,cnt); } } } printf("Case #%d: %d\n",iCase,maxn); } return 0;}
- 哈理工OJ 2116 Maximum continuous product(思维的体操)
- hrbust/哈理工oj 2116 Maximum continuous product【水题】
- Hust oj 2116 Maximum continuous product(水题)
- HLG 2116 Maximum continuous product (最大连续积 DP)
- 哈理工 OJ 2215 Angle(简单的思维题)
- 哈理工OJ 1909 理工门外的树(思维题目)
- (06-06)思维的体操
- 哈理工oj hrbust 2267 从前的运算符【思维】
- 哈理工OJ 1652(思维题)1652 小球移动.
- 哈理工OJ 1453 AAAAHH! Overbooked!(水题,换思维)
- 哈理工OJ 1431 摞盘子 (思维水题)
- 哈理工OJ 1037组合数末尾的零(思维)
- 哈理工OJ 2248 开锁魔法1(简单的思维题目)
- 哈理工OJ 1304 13哥的机器人(思维题)
- 哈理工OJ 2090 背包【思维】
- 哈理工OJ 2171 做菜【思维】
- 2016/9/1 2 Maximum Continuous Product
- LA3708 Graveyard --思维的体操
- 大牛的github-机器学习算法
- jzoj4467 数字方阵
- Eclipse安装后jdk和tomacat与以前项目不匹配解决办法
- Servlet中转发和重定向的路径问题以及表单提交路径问题
- Android动态加载技术 简单易懂的介绍方式
- 哈理工OJ 2116 Maximum continuous product(思维的体操)
- struts2拦截器(二) 自定义拦截器
- define宏定义中的#,##,@#及\符号
- Stanford机器学习---第一讲. Introduction of machine learning
- MyEclipse设置统一编码格式
- 15、Java Web 路径问题
- OGNL简介
- 1104. Sum of Number Segments
- TCP/IP协议族各层的协议汇总