hrbust/哈理工oj 2116 Maximum continuous product【水题】
2016-04-27 19:09
531 查看
Maximum continuous product
Time Limit: 1000 MS Memory Limit: 32768 K
Total Submit: 107(37 users) Total Accepted: 33(29 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
Source
ACM-ICPC黑龙江省第九届大学生程序设计竞赛选拔赛(2)
竟然直接暴力就能过T___T害我wa了好久T-T
AC代码:
Time Limit: 1000 MS Memory Limit: 32768 K
Total Submit: 107(37 users) Total Accepted: 33(29 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
Source
ACM-ICPC黑龙江省第九届大学生程序设计竞赛选拔赛(2)
竟然直接暴力就能过T___T害我wa了好久T-T
AC代码:
#include<stdio.h> #include<string.h> using namespace std; int a[100000]; int main() { int t; int kase=0; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&a[i]); } int output=0; int cnt=0; int flag=0; 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&&cnt>output){output=cnt;} } } printf("Case #%d: %d\n",++kase,output); } } /* 100 4 -2 2 2 2 4 -2 2 0 2 4 2 -2 2 0 8 2 -2 2 0 2 -2 2 2 10 2 -2 -2 2 2 2 -2 2 0 -2 10 0 2 2 -2 2 0 -2 0 0 0 8 2 0 2 -2 2 2 -2 2 */
相关文章推荐
- 【Realflow】Daemons - Gravity节点翻译
- 快速排序
- setting.xml 配置详解
- 团队任务四(无图)
- hdoj2008 (java)数值统计
- UIButton 无法点击的问题
- 【Realflow】Domain 节点翻译
- 在SQL Server中出现 “无法打开用户默认数据库,登录失败” 是什么原因?4046错误
- lucene学习笔记
- Tomcat for windows, Chrome for ubuntu
- JAVA_HOME的小问题
- ajax与this
- 18、IO流-标准输入输出流
- 单源最短路径 --Dijkstra算法-通过边实现松弛
- Zabbix利用msmtp+mutt发送邮件报警
- nyoj 45棋盘覆盖
- BZOJ 4517: [Sdoi2016]排列计数 错排公式
- Groovy入门教程
- 大规模密集型网络
- hdoj2007(java)平方和与立方和