当前位置:网站首页>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.
边栏推荐
- For the problem that Folium map cannot be displayed, the temporary solution is as follows
- Xpt2046 four wire resistive touch screen
- 睿智的目标检测23——Pytorch搭建SSD目标检测平台
- Lseek error
- Deux séquences ergodiques connues pour construire des arbres binaires
- Introduction to dynamic planning I, BFS of queue (70.121.279.200)
- Experiment collection of University "Fundamentals of circuit analysis". Experiment 4 - Research on linear circuit characteristics
- Soul torture, what is AQS???
- 已知两种遍历序列构造二叉树
- [leetcode] 577 reverse word III in string
猜你喜欢

Ant group's large-scale map computing system tugraph passed the national evaluation
![[leetcode] 1162 map analysis](/img/9a/d04bde0417d4d5232950a4e260eb91.png)
[leetcode] 1162 map analysis

Experiment collection of University "Fundamentals of circuit analysis". Experiment 6 - observation and measurement of typical signals

GraphX 图计算实践之模式匹配抽取特定子图

Pattern matching extraction of specific subgraphs in graphx graph Computing Practice

Traversal before, during and after binary tree

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

Experiment collection of University "Fundamentals of circuit analysis". Experiment 4 - Research on linear circuit characteristics

Finally, I understand the event loop, synchronous / asynchronous, micro task / macro task, and operation mechanism in JS (with test questions attached)

How to import a billion level offline CSV into Nepal graph
随机推荐
lseek 出错
Astra: could not open "2bc5/ [email protected] /6“: Failed to set USB interface
基于 Nebula Graph 构建百亿关系知识图谱实践
Thoroughly understand browser strong cache and negotiation cache
使用 percona 工具给 MySQL 表加字段中断后该如何操作
[leetcode] 877 stone game
How to use percona tool to add fields to MySQL table after interruption
Deux séquences ergodiques connues pour construire des arbres binaires
Wavedec2 in MATLAB, talk about the wavedec2 function [easy to understand]
Nebula Graph & 数仓血缘关系数据的存储与读写
6096. Success logarithm of spells and potions
图数据库|Nebula Graph v3.1.0 性能报告
SQL FOREIGN KEY
/bin/ld: 找不到 -lxslt
Basic knowledge of cryptography
Some problems about pytorch extension
《大学“电路分析基础”课程实验合集.实验七》丨正弦稳态电路的研究
6096. 咒语和药水的成功对数
Name of institution approved in advance
[leetcode] 977 square of ordered array


