标签:Educational Rated const int ll Codeforces long cin sum
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/\(\sum_1^i\)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;
}
我好弱。。。
标签:Educational,Rated,const,int,ll,Codeforces,long,cin,sum 来源: https://www.cnblogs.com/KeepInCode/p/14347832.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。