当前位置:网站首页>Codeforces Round #797 (Div. 3) A—E
Codeforces Round #797 (Div. 3) A—E
2022-07-02 06:10:00 【我wa的一声就哭出来了】
先放个当天打完发的吐槽:
今天cf真恶心,先卡b卡几十分钟,过完然后迅速过c后又卡d,实在想不出来于是去写了e,过完e发现e过了两千人d过了七千人,灰溜溜的继续写d,结果前缀和过了,给我恶心的,幸好看见过的那么多人没想dp,不然直接寄。
A. Print a Pedestal (Codeforces logo?)
题意题解略
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e5+7;
int main() {
int t;cin>>t;
while(t--){
int n;
cin>>n;
int now=n%3;
if(now==0){
cout<<n/3<<" "<<n/3+1<<" "<<n/3-1<<endl;
}
else if(now==1){
cout<<n/3<<" "<<n/3+1+1<<" "<<n/3-1<<endl;
}
else {
cout<<n/3+1<<" "<<n/3+1+1<<" "<<n/3-1<<endl;
}
}
return 0;
}
B. Array Decrements
题意:
每次操作可以使全部数字-1,如果变至0则不再减少。
题解:
除了可归0的直接求差值即可,要求所有差值全部相等,归0的差值小于等于那个需要恒等的差值。
wa:卡b不是因为思路难,是我以第一个位置做差值,忘记了第一个位置是归0的情况不可作为参考。需要特判出真正的【差值】。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+7;
int a[maxn],b[maxn];
#define sc scanf
int main() {
int t;cin>>t;
while(t--){
int n;
cin>>n;
for(int i=1;i<=n;i++)sc("%d",&a[i]);
for(int i=1;i<=n;i++)sc("%d",&b[i]);
int c=INT_MAX;
for(int i=1;i<=n;i++){
if(b[i]!=0)
{
c=a[i]-b[i];continue;
}
}
if(c<0){
cout<<"NO"<<endl;
continue;
}
else if(c==INT_MAX){
cout<<"YES"<<endl;
continue;
}
int f=1;
for(int i=1;i<=n;i++){
if(b[i]==0){
if(a[i]<=c)continue;
}
if(a[i]-b[i]!=c){
f=0;break;
}
}
if(f)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
C. Restoring the Duration of Tasks
题意题解略
注:根据条件知道不存在上一个还没结束但是下一个已经结束,而我考虑本情况多写了一个max,删去无影响。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+7;
int a[maxn],b[maxn];
#define sc scanf
#define pr printf
int main() {
int t;cin>>t;
while(t--){
int n;
cin>>n;
for(int i=1;i<=n;i++)sc("%d",&a[i]);
for(int i=1;i<=n;i++)sc("%d",&b[i]);
cout<<b[1]-a[1];
for(int i=2;i<=n;i++){
pr(" %d",max(0,b[i]-max(a[i],b[i-1])));
}
pr("\n");
}
return 0;
}
D. Black and White Stripe
题意:
选出最少染色数目使长为k的子序列为全黑。
题解:
个人思考部分:
乍一看觉得要用一些算法,但是div3(),过的人又很多。属于是又觉得是纯思维,又害怕是dp。怎么也想不出来纯思维解法,又不愿意用算法,故卡之。
其实用一下前缀和稍微优化一下直接暴力就可以了,我们直接算出所有区间长度为k的子序列—>算出所有的染色可能,取最小即可。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+7;
int a[maxn],b[maxn];
#define sc scanf
#define pr printf
int main() {
int t;cin>>t;
while(t--){
int n,m;cin>>n>>m;
string s;cin>>s;
if(s[0]=='W')a[0]=1;
else a[0]=0;
for(int i=0;i<n;i++){
if(s[i]=='W')a[i]=a[i-1]+1;
else a[i]=a[i-1];
}
int mmin=a[m-1];
for(int i=m;i<n;i++){
mmin=min(a[i]-a[i-m],mmin);
}
//cout<<"ans:";
cout<<mmin<<endl;
}
return 0;
}
E. Price Maximization
题意:
第一眼:题目很长还向下取整,一定是个很难的数学题吧!(个屁)
其实感觉和D差不多难度:n个数,两两相加除以k(向下取整),如何使答案最大?
题解:
把所有的‘k’先取出来。这个是一定不会被向下取整损失掉的1,全部相加存入ans。
处理剩下的数,其实也就是余数部分了,sort拍下序。双指针遍历保证最大,此部分具见代码,当有两个数相加大于k则可以ans++。
最后的ans就是答案。
没开 ll wa了一发()
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+7;
ll a[maxn],b[maxn];
#define sc scanf
#define pr printf
int main() {
int t;cin>>t;
while(t--){
ll n,m;cin>>n>>m;
ll cnt=0;
for(int i=1;i<=n;i++){
sc("%lld",&a[i]);
if(a[i]>=m){
cnt+=a[i]/m;
a[i]%=m;
}
}
sort(a+1,a+n+1);
ll l=1,r=n;
while(l<r){
if(a[l]+a[r]>=m){
cnt++;
l++;
r--;
}
else l++;
}
//cout<<"ans:";
cout<<cnt<<endl;
}
return 0;
}
边栏推荐
- Shenji Bailian 3.53-kruskal
- MUI底部导航的样式修改
- JWT tool class
- 锐捷EBGP 配置案例
- Compte à rebours de 3 jours pour l'inscription à l'accélérateur de démarrage Google Sea, Guide de démarrage collecté à l'avance!
- Go learning notes integration
- 队列(线性结构)
- uni-app开发中遇到的问题(持续更新)
- No subject alternative DNS name matching updates. jenkins. IO found, the reason for the error and how to solve it
- Stc8h8k series assembly and C51 actual combat - digital display ADC, key serial port reply key number and ADC value
猜你喜欢

500. Keyboard line

Deep learning classification network -- Network in network

Sumo tutorial Hello World

锐捷EBGP 配置案例

Jetpack Compose 与 Material You 常见问题解答

Contest3147 - game 38 of 2021 Freshmen's personal training match_ G: Flower bed

Redis Key-Value数据库【初级】

LeetCode 90. Subset II

队列(线性结构)

官方零基础入门 Jetpack Compose 的中文课程来啦!
随机推荐
Community theory | kotlin flow's principle and design philosophy
Scheme and implementation of automatic renewal of token expiration
深入了解JUC并发(一)什么是JUC
keepalived安装使用与快速入门
Replace Django database with MySQL (attributeerror: 'STR' object has no attribute 'decode')
Reading classic literature -- Suma++
步骤详解 | 助您轻松提交 Google Play 数据安全表单
借力 Google Cloud 基础设施和着陆区,构建企业级云原生卓越运营能力
It is said that Kwai will pay for the Tiktok super fast version of the video? How can you miss this opportunity to collect wool?
Bgp Routing preference Rules and notice Principles
Eco express micro engine system has supported one click deployment to cloud hosting
神机百炼3.53-Kruskal
BGP中的状态机
深入了解JUC并发(二)并发理论
日期时间API详解
LeetCode 39. Combined sum
Picture clipping plug-in cropper js
Little bear sect manual query and ADC in-depth study
Network related knowledge (Hardware Engineer)
Ti millimeter wave radar learning (I)