[DOFY]广播体操

learningman 2月 07, 2018

T15301】广播体操

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;int group[50005];int ans=0;bool trfl;int main(){ /*freopen("liuce.in","r",stdin); freopen("liuce.out","w",stdout);*/ memset(group,0,sizeof(group)); int groupnum; scanf("%d",&groupnum); for(int i=0;i<=(groupnum-1);i++) scanf("%d",&group[i]); for(int i=0;i<=(groupnum-1);i++) { trfl=1; int j=0; j=i; while(trfl) { if(group[j+1]>=group[j]) j++; else { group[i]=(j-i+1)*group[i]; trfl=false; } } } for(int i=0;i<=(groupnum-1);i++) { if(group[i]>ans) ans=group[i]; } printf("%d",ans); //可以优化,一个group[i]可能被扫描多次; /*fclose(stdin); fclose(stdout);*/ return 0;}

得高人相助,重写。
A.png

#include <bits/stdc++.h>#define maxn 50001using namespace std;int ans=0;int n;int A[maxn];int Acount[maxn];int compute(int x){ //printf("compute\n"); int countnum=1; int exit1=1,exit2=1; int xswap1=x-1,xswap2=x+1; while(exit1)//向左搜 { if(A[xswap1]>=A[x]&&xswap1>=0) { countnum++; xswap1--; } else { exit1=0; } } while(exit2)//向右搜 { if(A[xswap2]>=A[x]&&xswap1<=n-1) { countnum++; xswap2++; } else { exit2=0; } } return countnum; }int main(){ scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&A[i]); for(int i=0;i<n;i++) { Acount[i]=A[i]*compute(i); } for(int i=0;i<n;i++) { ans=max(ans,Acount[i]); } printf("%d",ans); return 0;}

挂四个构造数据点。。。
D.png

本文采用 CC BY-NC-SA 3.0 协议进行许可,在您遵循此协议的情况下,可以自由共享与演绎本文章。
本文链接:https://learningman.top/archives/38.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注




you're currently offline