zoukankan      html  css  js  c++  java
  • codeforces 1313C1 Skyscrapers (easy version) 暴力枚举

    对于每座高楼,两侧的楼不能同时高于这座楼
    于是就是一个关于高楼的单峰函数

    暴力枚举以每个位置作为最高点的答案
    注意开 long long

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<iostream>
    #include<cmath>
    #include<stack>
    #include<queue>
    using namespace std;
    typedef long long ll;
    
    const int maxn = 100010;
    
    int n;
    ll a[maxn],b[maxn],ans[maxn];
    
    ll read(){ ll s=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f; }
    
    int main(){
    	n = read();
    	for(int i=1;i<=n;i++) a[i] = read();
    	
    	ll ma = 0;
    	for(int i=1;i<=n;i++){
    		ll h = a[i],sh = a[i];
    		b[i] = a[i];
    		for(int j=i-1;j>=1;j--){
    			if(a[j] >= h){
    				b[j] = h;
    				sh += b[j];
    			}else{
    				h = a[j];
    				b[j] = h;
    				sh += b[j];
    			}
    		}
    		h = a[i];
    		for(int j=i+1;j<=n;j++){
    			if(a[j] >= h){
    				b[j] = h;
    				sh += b[j];
    			}else{
    				h = a[j];
    				b[j] = h;
    				sh += b[j];
    			}
    		}
    		if(sh>ma){
    			ma = sh;
    			for(int j=1;j<=n;j++){
    				ans[j] = b[j];
    			}
    		}
    	}
    	
    	for(int i=1;i<=n;i++) printf("%lld ",ans[i]); printf("
    "); 
    	
    	return 0;
    }
    
  • 相关阅读:
    HDOJ-1106
    二进制神题--一千个苹果问题
    HDOJ-2160
    HDOJ-2058
    HDOJ-2045
    HDOJ-2034
    HDOJ-2054
    HDOJ-2036
    F
    B
  • 原文地址:https://www.cnblogs.com/tuchen/p/13818009.html
Copyright © 2011-2022 走看看