当前位置:网站首页>2020.4.12 byte written test questions B DP D monotone stack
2020.4.12 byte written test questions B DP D monotone stack
2022-07-02 15:49:00 【ccsu_ deer】
A Simple exchange
Water problem ..
B-- Folding stick
The solution comes from friends
f[i][j]: The first i The maximum value of wooden sticks is j The minimum number of disassembly to make the previous conditions meet
Greedy to get a minimum value of this kind of split stick X And times S
f[i][j]=max(f[i-1][k]+s) k<=xIn fact, that is Every stick a[i] The maximum enumeration value is len ( On the far right is len) And the leftmost : a[i]%len Calculate the minimum disassembly :s=a[i]/len+((a[i]%len==0)?0:1)-1
According to each position len The leftmost number is either a[i]%len Or len How to calculate What about the legal maximum on the far left ?pos+1 Number Average a[i] Just fine k=a[i]/(pos+1)
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL a[3005], f[3005][3005];
int main() {
int n; scanf("%d", &n);
for(int i=1; i<=n; i++){
scanf("%lld", &a[i]);
}
memset(f, 7, sizeof(f));
for(int i=0; i<3005; i++) f[0][i]=0;
for(int i=1; i<=n; i++){
for(int len=1; len<3005; len++){
if(len>a[i]){
f[i][len]=f[i][len-1];
continue;
}
LL pos=a[i]/len+((a[i]%len==0)?0:1)-1;// according to mi len len len Number of cuts pos
LL mi=((a[i]%len==0)?len:(a[i]%len));
//pos*len+mi==a[i]
LL x=(pos*len+mi)/(pos+1);// cut pos Dao you pos+1 A place ,a[i] To give evenly to pos+1 A position is the maximum legal value x
//printf("mi:%lld x:%lld\n",mi,x);
f[i][len]=f[i-1][x]+pos;
f[i][len]=min(f[i][len], f[i][len-1]);
//cout<<i<<" "<<len<<" "<<f[i][len]<<endl;
}
}
LL ans=1<<30;
for(int i=1; i<=a[n]; i++){
ans=min(ans, f[n][i]);
}
printf("%lld\n", ans);
return 0;
}
/*
5
3 5 13 9 12
ans:1
5
5 4 3 2 1
ans:
*/
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
C-- Coupon
Yes a Sort ,b[i] stay a Just score two points .
D-- Stand tall Look far
Classic monotonous stack question
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N=1e6+10;
int a[N],ans[N],n,m,l[N],r[N];
int main()
{
int _;cin>>_;while(_--)
{
scanf("%d",&n);
rep(i,1,n) scanf("%d",&a[i]);
stack<int>sta;
rep(i,1,n) l[i]=r[i]=i;
for(int i=1;i<=n;++i){
if(sta.size()==0) sta.push(i);
else{
while(sta.size()&&a[i]>=a[sta.top()]) {
sta.pop();
}
if(sta.size()) l[i]=sta.top()+1;
else l[i]=1;
sta.push(i);
}
}
while(sta.size()) sta.pop();
for(int i=n;i;--i){
if(sta.size()==0) sta.push(i);
else{
while(sta.size()&&a[i]>=a[sta.top()]) {
sta.pop();
}
if(sta.size()) {
r[i]=sta.top()-1;
}
else r[i]=n;
sta.push(i);
}
}
rep(i,1,n)
{
printf("%d ",r[i]-l[i]);
}
puts("");
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
边栏推荐
- 数组和链表的区别浅析
- 【LeetCode】200-岛屿数量
- 6095. 强密码检验器 II
- Wise target detection 23 - pytoch builds SSD target detection platform
- [development environment] install Visual Studio Ultimate 2013 development environment (download software | install software | run software)
- 【Salesforce】如何确认你的Salesforce版本?
- [leetcode] 1905 statistics sub Island
- For the problem that Folium map cannot be displayed, the temporary solution is as follows
- How to use percona tool to add fields to MySQL table after interruption
- 《大学“电路分析基础”课程实验合集.实验四》丨线性电路特性的研究
猜你喜欢

XPT2046 四线电阻式触摸屏
![[development environment] install the Chinese language pack for the 2013 version of visual studio community (install test agents 2013 | install visual studio 2013 simplified Chinese)](/img/cf/38e4035c3b318814672f21c8a42618.jpg)
[development environment] install the Chinese language pack for the 2013 version of visual studio community (install test agents 2013 | install visual studio 2013 simplified Chinese)

Review materials for the special topic of analog electronics with all essence: basic amplification circuit knowledge points

树-二叉搜索树

Aiko ai Frontier promotion (7.2)

Two traversal sequences are known to construct binary trees

基于 Nebula Graph 构建百亿关系知识图谱实践

Xpt2046 four wire resistive touch screen

使用 percona 工具给 MySQL 表加字段中断后该如何操作
![[network security] network asset collection](/img/3e/6665b5af0dedfcbc7bd548cc486878.png)
[network security] network asset collection
随机推荐
[leetcode] 1905 statistics sub Island
奥比中光 astra: Could not open “2bc5/[email protected]/6“: Failed to set USB interface
Comment réaliser un graphique Nebula d'importation CSV hors ligne de niveau milliard
如何實現十億級離線 CSV 導入 Nebula Graph
lseek 出错
将点云坐标转换成世界坐标的demo
蚂蚁集团大规模图计算系统TuGraph通过国家级评测
How to import a billion level offline CSV into Nepal graph
二叉树前,中,后序遍历
Moveit 避障路径规划 demo
Xpt2046 four wire resistive touch screen
动态规划入门二(5.647.62)
beforeEach
[leetcode] 1140 stone game II
爱可可AI前沿推介(7.2)
(5) Flink's table API and SQL update mode and Kafka connector case
Experiment collection of University Course "Fundamentals of circuit analysis". Experiment 5 - Research on equivalent circuit of linear active two terminal network
GraphX 图计算实践之模式匹配抽取特定子图
Use ffmpeg command line to push UDP and RTP streams (H264 and TS), and ffplay receives
/Bin/ld: cannot find -lxml2


