Codeforces Round #622 (Div. 2) C1. Skyscrapers (easy version)(简单版本暴力)
This is an easier version of the problem. In this version n≤1000n≤1000
The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the company has already bought nn plots along the highway and is preparing to build nn skyscrapers, one skyscraper per plot.
Architects must consider several requirements when planning a skyscraper. Firstly, since the land on each plot has different properties, each skyscraper has a limit on the largest number of floors it can have. Secondly, according to the design code of the city, it is unacceptable for a skyscraper to simultaneously have higher skyscrapers both to the left and to the right of it.
Formally, let's number the plots from 11 to nn . Then if the skyscraper on the ii -th plot has aiai floors, it must hold that aiai is at most mimi (1≤ai≤mi1≤ai≤mi ). Also there mustn't be integers jj and kk such that j<i<kj<i<k and aj>ai<akaj>ai<ak . Plots jj and kk are not required to be adjacent to ii .
The company wants the total number of floors in the built skyscrapers to be as large as possible. Help it to choose the number of floors for each skyscraper in an optimal way, i.e. in such a way that all requirements are fulfilled, and among all such construction plans choose any plan with the maximum possible total number of floors.
The first line contains a single integer nn (1≤n≤10001≤n≤1000 ) — the number of plots.
The second line contains the integers m1,m2,…,mnm1,m2,…,mn (1≤mi≤1091≤mi≤109 ) — the limit on the number of floors for every possible number of floors for a skyscraper on each plot.
Print nn integers aiai — the number of floors in the plan for each skyscraper, such that all requirements are met, and the total number of floors in all skyscrapers is the maximum possible.
If there are multiple answers possible, print any of them.
5
1 2 3 2 1
1 2 3 2 1
3
10 6 8
10 6 6
大意是让你填在n个位置填数,有两个限制:1.每个位置的数不能超过那个位置的最大范围。2.填的数的左右两边不能有比它大的数。
简单版暴力就可以过,枚举1e3个位置,可以看出是一个类似尖峰的形状,分别往两边递减,找到那个能取最大值的位置,输出即可。O(n^2)复杂度对于1e3可过。
不开long long见祖宗!!!
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
int a[];
int out[];
int main()
{
int n,i,j,k;
cin>>n;
int num=-;
long long ans=;
for(i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(i=;i<=n;i++)
{
long long cnt=;
cnt+=a[i];
out[i]=a[i];
for(j=i-;j>=;j--)
{
cnt+=min(a[j],out[j+]);
out[j]=min(a[j],out[j+]);
}
for(j=i+;j<=n;j++)
{
cnt+=min(a[j],out[j-]);//在两个限制之下取最小的
out[j]=min(a[j],out[j-]);
}
if(cnt>=ans)
{
num=i;
ans=cnt;
}
}
out[num]=a[num];
for(j=num-;j>=;j--)
{
out[j]=min(a[j],out[j+]);
}
for(j=num+;j<=n;j++)
{
out[j]=min(a[j],out[j-]);
}
for(i=;i<=n;i++)
{
cout<<out[i]<<' ';
}
return ;
}
Codeforces Round #622 (Div. 2) C1. Skyscrapers (easy version)(简单版本暴力)的更多相关文章
- Codeforces Round #622(Div 2) C1. Skyscrapers (easy version)
题目链接: C1. Skyscrapers (easy version) 题目描述: 有一行数,使得整个序列满足 先递增在递减(或者只递增,或者只递减) ,每个位置上的数可以改变,但是最大不能超过原来 ...
- Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version)(单调栈,递推)
Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version) 题意: 你是一名建筑工程师,现给出 n 幢建筑的预计建设高度,你想建成峰状, ...
- Codeforces Round #622 (Div. 2).C2 - Skyscrapers (hard version)
第二次写题解,请多多指教! http://codeforces.com/contest/1313/problem/C2 题目链接 不同于简单版本的暴力法,这个数据范围扩充到了五十万.所以考虑用单调栈的 ...
- Codeforces Round #622 (Div. 2) C2 - Skyscrapers (hard version) 单调栈
从左往右扫,找到比第i个小的第一个数字,l[i] = l[last] + (i - last) * m[i],用单调栈O(n)维护这个过程,再从右往左扫,同理可以算出r数组,注意一下long long ...
- Codeforces Round #622 (Div. 2)C2 Skyscrapers最大"尖"性矩形,思维||分治
题:https://codeforces.com/contest/1313/problem/C2 题意:给出n个数,分别代表第i个位置所能搭建的最大高度,问以哪一个位置的塔的高度为基准向左的每一个塔都 ...
- Codeforces Round #570 (Div. 3) E. Subsequences (easy version) (搜索,STL)
题意:有一长度为\(n\)的字符串,要求得到\(k\)不同的它的子序列(可以是空串),每个子序列有\(|n|-|t|\)的贡献,求合法情况下的最小贡献. 题解:直接撸个爆搜找出所有子序列然后放到set ...
- Codeforces Round #622 (Div. 2) 1313 C1
C1. Skyscrapers (easy version) time limit per test1 second memory limit per test512 megabytes inputs ...
- Codeforces Round #622 (Div. 2) B. Different Rules(数学)
Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...
- Codeforces Round #622 (Div. 2) A. Fast Food Restaurant(全排列,DFS)
Codeforces Round #622 (Div. 2) A. Fast Food Restaurant 题意: 你是餐馆老板,虽然只会做三道菜,上菜时还有个怪癖:一位客人至少上一道菜,且一种菜最 ...
随机推荐
- Linux零碎002
1.if else就近原则: 2.指针位数与机器地址总线宽度一致: 3.数组即常量指针,用法和指针类似,在操作指针时:p与&p[0]含义一样: 4.编译器按照内存递减的方式来分配变量.
- PP: Overviewing evolution patterns of egocentric networks by interactive construction of spatial layouts
Problem: get an overall picture of how ego-networks evolve is a common challenging task. Existing te ...
- C++-main函数与命令行参数
1.main函数的概念 C语言中main函数称之为主函数 —个C程序是从main函数开始执行的 下面的main函数定义正确吗? //1 main(){ } //2 void main(){ } //3 ...
- SVN提交时没有写注释
会报错: Error: Commit blocked by pre-commit hook (exit code 1) with output: Error: [Commit failed]: Emp ...
- Log4j的isdebugEnabled的作用
转自:https://www.iteye.com/blog/zhukewen-java-1174017 在项目中我们经常可以看到这样的代码: if (logger.isDebugEnabled()) ...
- 接口自动化框架(Pytest,Allure,Yaml)
框架链接:https://www.jianshu.com/p/e31c54bf15ee 目前是基于他的框架做了些改动(主要是session.action()和json格式传参). 后续优化,应该主要思 ...
- JavaScript可视化运行工具推荐
事件循环.执行栈和任务队列可视化 这个宏任务.微任务,自带例子,也可以自己编辑,不过超过5s的例子就不行 JavaScript Visualizer Tyler Mcginnis大佬的Advanced ...
- Java第一个程序HelloWorld
1.创建一个java源文件:HelloWorld.java public class HelloWorld{ public static void main(String[] args){ Syste ...
- [NOIP2018(PJ)] 摆渡车
题目链接 题意 有 $n$ 个同学在等车,每位同学从某时刻开始等车,相邻两趟车之间至少间隔 $m$ 分钟.凯凯可以任意安排发车时间,求所有同学等车时间之和的最小值. 分析 这题首先能想到是动态规划 很 ...
- C++-POJ1017-Packets
贪心算法,思路见代码 本来想搜索,结果有O(1)的算法,我佛了 其实每一种6x6的方案可以打表预处理,然后dp or search 但是既然可以贪心何乐而不为呢? #include <set&g ...