hdu-4561 连续最大积( 水题)
http://acm.hdu.edu.cn/showproblem.php?pid=4561
求连续最大积。
他妈的狗逼思路到底咋说。。。。。
思路是 %&*()*(&……))*)*&)……%……%**(*()()——+(**(……&*……%&*……Y%^&%%^*&&(&*(&*(*&()*&(**……&%……&
%&……%&……&(&……* ())&(**&……%*&&*((——+——)&(**……&%……&……*&%¥S%^&$**&%%&^A *&^&***(^U(*)()^(*&^&*(()&^**&*$%YT^&^%&^^&%%^%&%^&%&^
%&^&(^&&(*&_)(&^*^U&*&OP)_(+_{()*&*&%^&%$&^$^%$#%^&*^&)(**)_(_+................................................
懂了吧。。。。。
我来翻译;
其实思路就是找断点,断点就是0,也就是以0为分界,将所给的数字串分成k段 比如2220-2-2-22022;
就可以分成222 -2-2-22 22三段,因为如果选入0的话乘积肯定是0,题目说积小于等于0的结果都为0,所以以0分界。
那么就是计算每段的2的个数,和-2的个数,如果段内的-2个数是偶数个,那么这段的长度直接和maxx比较,更新maxx,
如果是奇数个,假设n个的话从段的左边循环到有边直到遇到第n个-2跳出,那么前面不就是偶数个-2了么。
那么再从右端循环到左端,直到遇到第n个-2跳出,比较两次的大小,大的就是本段连续最大积。
因为要连续而且又只多一个-2,所以说最大要么左连续,要么右连续。
最后maxx就是最大的了;
1 #include<stdio.h>
2 #include<iostream>
3 #include<stdlib.h>
4 #include<string.h>
5 #include<math.h>
6 typedef struct pp
7 {
8 int x;
9 int y;
10 int x1;
11 int y1;
12 } ss;
13 using namespace std;
14 int main(void)
15 {
16 int a[10005];
17 ss cou[10005];
18 int n,i,j,k,p,q;
19 scanf("%d",&n);
20 for(i=1; i<=n; i++)
21 {
22 scanf("%d",&k);
23 for(j=0; j<k; j++)
24 {
25 scanf("%d",&a[j]);
26 cou[j].x=0;
27 cou[j].y=0;
28 cou[j].x1=0;
29 cou[j].y1=0;
30 }
31 if(a[0]>0)
32 {
33 cou[0].x++;
34 }
35 else if(a[0]<0)
36 {
37 cou[0].y++;
38 }
39 int maxx=0;
40 for(j=1; j<k; j++)//从断点到到本个点有多2 -2(从左循环)
41 {
42 if(a[j]>0)
43 {
44 cou[j].x=cou[j-1].x+1;
45 cou[j].y=cou[j-1].y;
46 }
47 else if(a[j]<0)
48 {
49 cou[j].y=cou[j-1].y+1;
50 cou[j].x=cou[j-1].x;
51 }
52
53 }
54 if(a[k-1]>0)
55 {
56 cou[k-1].x1++;
57 }
58 else if(a[k-1]<0)
59 {
60 cou[k-1].y1++;
61 }
62 for(j=k-2; j>=0; j--)//从断点到到本个点有多2 -2(从右循环)
63 {
64 if(a[j]>0)
65 {
66 cou[j].x1=cou[j+1].x1+1;
67 cou[j].y1=cou[j+1].y1;
68 }
69 else if(a[j]<0)
70 {
71 cou[j].y1=cou[j+1].y1+1;
72 cou[j].x1=cou[j+1].x1;
73 }
74
75 }
76 for(j=0; j<k; j++)
77 {
78 if(cou[j].y%2==0)
79 {
80 if(maxx<cou[j].x+cou[j].y)
81 {
82 maxx=cou[j].x+cou[j].y;
83 }
84 }
85 if(cou[j].y1%2==0)
86 {
87 if(maxx<cou[j].x1+cou[j].y1)
88 {
89 maxx=cou[j].x1+cou[j].y1;
90 }
91 }
92 }
93 printf("Case #%d: %d\n",i,maxx);
94 }
95 return 0;
96 }
hdu-4561 连续最大积( 水题)的更多相关文章
- hdu 1005:Number Sequence(水题)
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu 2041:超级楼梯(水题,递归)
超级楼梯 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Su ...
- HDU 5578 Friendship of Frog 水题
Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...
- HDU 5590 ZYB's Biology 水题
ZYB's Biology Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid ...
- HDU 5538 L - House Building 水题
L - House Building Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...
- hdu 1018:Big Number(水题)
Big Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDOJ/HDU 1328 IBM Minus One(水题一个,试试手)
Problem Description You may have heard of the book '2001 - A Space Odyssey' by Arthur C. Clarke, or ...
- HDOJ(HDU) 2090 算菜价(简单水题、)
Problem Description 妈妈每天都要出去买菜,但是回来后,兜里的钱也懒得数一数,到底花了多少钱真是一笔糊涂帐.现在好了,作为好儿子(女儿)的你可以给她用程序算一下了,呵呵. Input ...
- HDOJ(HDU) 1555 How many days?(水题)
Problem Description 8600的手机每天消费1元,每消费K元就可以获赠1元,一开始8600有M元,问最多可以用多少天? Input 输入包括多个测试实例.每个测试实例包括2个整数M, ...
随机推荐
- day07 MySQL索引事务
day07 MySQL索引事务 昨日内容回顾 pymysql模块 # 链接数据库都是使用这个模块的 # 创建链接 import pymysql conn = pymysql.connect( host ...
- 13. 搭建arm-linux-gcc交叉编译环境
1.下载工具并解压 下载路径 http://www.arm9.net/download.asp 将 arm-linux-gcc-4.5.1-v6-vfp-20120301.tgz 拷贝到 Linux ...
- TLSv1.3 Support:主流 Web 客户端和服务端对 TLSv1.3 的支持情况
TLSv1.3 Support:主流 Web 客户端和服务端对 TLSv1.3 的支持情况 请访问原文链接:https://sysin.org/blog/tlsv1-3-support/,查看最新版. ...
- JS模块化,Javascript 模块化管理的历史
模块管理这个概念其实在前几年前端度过了刀耕火种年代之后就一直被提起. 直接回想起来的就是 cmd amd commonJS 这三大模块管理的印象.接下来,我们来详细聊聊. 一.什么是模块化开发 为了让 ...
- 【leetcode】121. Best Time to Buy and Sell Stock(股票问题)
You are given an array prices where prices[i] is the price of a given stock on the ith day. You want ...
- 容器之分类与各种测试(三)——forward_list的用法
forward_list是C++11规定的新标准单项链表,slist是g++以前的规定的单项链表 例程 #include<stdexcept> #include<string> ...
- 单链表的模板类(C++)
/*header.h*/#pragma once #include<iostream> using namespace std; template<class T> struc ...
- Linux基础命令---ftp
ftp ftp指令可以用来登录远程ftp服务器. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.Fedora. 1.语法 ftp [ ...
- Maven项目打包成war包并启动war包运行
1 项目打包 1.1 右键点击所需要打包的项目,点击如图所示 Maven clean,这里 Maven 会清除掉之前对这个项目所有的打包信息. 1.2进行完 Maven clean 操作后,在ecli ...
- highchars操作集合
一.tooltip 与鼠标指针的距离想调整tooltip和鼠标指针的距离,官方api 和中文api中都没写,只有轴 label.distance . 但我觉得应该有这个,看源码果然有 tooltip ...