Educational Codeforces Round 103 (Rated for Div. 2)
Educational Codeforces Round 103 (Rated for Div. 2)
https://codeforces.com/contest/1476
A. K-divisible Sum
思路
求出n个数之和为k的倍数的序列中的最大值并使它尽可能小。
首先我们考虑k个1的情况,如果无法满足,则求出距离n最近的k的倍数p(p>n),将(p-n)均分到n个1上,结果为1+(p-n)/n+((p-n)%n>0)。
Code
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int inf=0x3f3f3f3f;
typedef long long ll;
const int N=5007;
const ll mod=998244353;
int main(){
IO;
int t=1;
cin>>t;
while(t--){
int n,k;
cin>>n>>k;
int p=(n+k-1)/k*k;
p-=n;
int m=p/n;
cout<<1+m+(p%n>0)<<endl;
}
return 0;
}
B. Inflation
思路
题意为保证对于每个i:pi+1/pi<=k%都成立,如果存在某个i不成立,我们只有改变p0的值才是最优的,因为改变其他值可能会影响已经成立的不等式。
Code
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int inf=0x3f3f3f3f;
typedef long long ll;
const int N=5007;
const ll mod=998244353;
ll p[107],sum[107];
int main(){
IO;
int t=1;
cin>>t;
while(t--){
ll n,k;
cin>>n>>k;
for (int i = 1; i <= n; ++i)
{
cin>>p[i];
sum[i]=sum[i-1]+p[i];
}ll b=0;
for (int i = 1; i < n; ++i)
{
sum[i]+=b;
if(100ll*p[i+1]>sum[i]*k){
ll m=sum[i]*k;
ll x=(100ll*p[i+1]+k-1)/k;
b+=x-sum[i];
}
}cout<<b<<endl;
}
return 0;
}
D. Journey
思路
差一点做出来,时间到了
经过观察发现当从某个位置向右走时,只有R和L交替出现才会增加到访的城市数,向左走时,只有L和R交替出现才会增加城市数。
注意向右走时看的是后一位置的值,向左走看的是当前位置的值。
用四个数组分别记录左边和右边L和R交替出现的个数,最后加上1即使答案。
Code
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int inf=0x3f3f3f3f;
typedef long long ll;
const int N=3e5+7;
const ll mod=998244353;
int LL[N],LR[N],RR[N],RL[N];
char s[N];
int main(){
IO;
int t=1;
cin>>t;
while(t--){
int n;
cin>>n;
cin>>(s+1);
for (int i = 1; i <= n; ++i)
{
if(s[i]=='L')LL[i]=LR[i-1]+1;
if(s[i]=='R')LR[i]=LL[i-1]+1;
}
for (int i = n; i > 0; --i)
{
if(s[i]=='L')RL[i-1]=RR[i]+1;
if(s[i]=='R')RR[i-1]=RL[i]+1;
}
for (int i = 0; i <= n; ++i)
{
cout<<LL[i]+RR[i]+1<<" ";
LL[i]=LR[i]=RL[i]=RR[i]=0;
}cout<<endl;
}
return 0;
}
我好弱。。。
Code will change the world !
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】凌霞软件回馈社区,携手博客园推出1Panel与Halo联合会员
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 长文讲解 MCP 和案例实战
· Hangfire Redis 实现秒级定时任务,使用 CQRS 实现动态执行代码
· Android编译时动态插入代码原理与实践
· 解锁.NET 9性能优化黑科技:从内存管理到Web性能的最全指南
· 通过一个DEMO理解MCP(模型上下文协议)的生命周期
· 工良出品 | 长文讲解 MCP 和案例实战
· 多年后再做Web开发,AI帮大忙
· 一天 Star 破万的开源项目「GitHub 热点速览」
· 记一次 .NET某旅行社酒店管理系统 卡死分析
· 别再堆文档了,大模型时代知识库应该这样建