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 }
时间: 2024-08-08 09:37:10

hdu-4561 连续最大积( 水题)的相关文章

HDU 4561 连续最大积 (模拟题)

#include <iostream> #include<cstdio> using namespace std; int a[50000+100],n; int solve(int s,int e) { int i,cnt=0,st,ed,flag=1,ans=0; //if(s==n+1) return 0; for(i=s;i<e;i++) { if(a[i]==-2) { if(flag) { flag=0; st=i;//记录此区间内-2第一次出现的位置 } ed=

hdu 1999 不可摸数 水题。

不可摸数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7966    Accepted Submission(s): 2024 Problem Description s(n)是正整数n的真因子之和,即小于n且整除n的因子和.例如s(12)=1+2+3+4+6=16.如果任何数m,s(m)都不等于n,则称n为不可摸数. Input 包

HDU Senior&#39;s Gun (水题)

题意:给n把枪,m个怪兽,每把枪可消灭1怪兽,并获得能量=枪的攻击力-怪兽的防御力.求如何射杀能获得最多能量?(不必杀光) 思路:用最大攻击力的枪杀防御力最小的怪兽明显可获得最大能量.如果每把枪都去射杀刚好1点能量都拿不到的怪物,那简直等于把枪全丢掉. 1 //#pragma comment(linker,"/STACK:102400000,102400000") 2 #include <iostream> 3 #include <stdio.h> 4 #inc

HDU 5590 ZYB&#39;s Biology 水题

ZYB's Biology Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5590 Description ZYB(ZJ−267)在NOIP拿到600分之后开始虐生物题,他现在扔给你一道简单的生物题:给出一个DNA序列和一个RNA序列,问它们是否配对. DNA序列是仅由A,C,G,T组成的字符串,RNA序列是仅由A,C,G,U组成的字符串. DNA和RNA匹配当且仅当每

hdu 4847 Wow! Such Doge! 水题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4847 统计文本中一共有多少个“Doge” 水题 #include <cstring> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <cstdio> #includ

HDU 5578 Friendship of Frog 水题

Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5578 Description N frogs from different countries are standing in a line. Each country is represented by a lowercase letter. The distance betwee

杭电(hdu)2053 Switch Game 水题

Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 13113    Accepted Submission(s): 7970 Problem Description There are many lamps in a line. All of them are off at first. A series of o

HDU 1846 Brave Game (博弈水题)

题意:中文...你们懂得. 析:这个就是一个水题博弈,就是一个巴什博弈定理,直接就没有变,如果你们看过我写的那个,这个题绝对水过. 附地址:http://www.cnblogs.com/dwtfukgv/p/5517818.html 看完后就懂了吧,不用说了,直接上代码就OK. 代码如下: #include <iostream> #include <string> #include <vector> #include <algorithm> #include

HDU 1228 A + B (水题)

A + B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13260 Accepted Submission(s): 7797 Problem Description 读入两个小于100的正整数A和B,计算A+B. 需要注意的是:A和B的每一位数字由对应的英文单词给出. Input 测试输入包含若干测试用例,每个测试用例占一行,格式为"A