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;
    }
    
  • 相关阅读:
    [CF1469D] Ceil Divisions
    [CF632D] Longest Subsequence
    [CF1215E] Marbles
    [CF689D] Friends and Subsequences
    [CF707D] Persistent Bookcase
    [CF10D] LCIS
    [CF713C] Sonya and Problem Wihtout a Legend
    [CF1114E] Arithmetic Progression
    [CF1404B] Tree Tag
    [CF710E] Generate a String
  • 原文地址:https://www.cnblogs.com/tuchen/p/13818009.html
Copyright © 2011-2022 走看看