当前位置:网站首页>Codeforces Round #797 (Div. 3) A~E题解记录
Codeforces Round #797 (Div. 3) A~E题解记录
2022-06-09 08:19:00 【ILECY】
A. Print a Pedestal (Codeforces logo?)
A - Print a Pedestal (Codeforces logo?)
简单找个规律然后按照%3分类讨论就可以了
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define NOTLE ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'
#define T int TT;cin >> TT;while (TT--)
#define lint long long
#define pb push_back
#define eb emplace_back
int main(){
T{
int n;
cin >> n;
int a1=n/3,m=n%3;
if(m==0) cout << a1 << ' ' << a1+1 << ' ' << a1-1 <<endl;
if(m==1) cout << a1 << ' ' << a1+2 << ' ' << a1-1 <<endl;
if(m==2) cout << a1+1 << ' ' << a1+2 << ' ' << a1-1 <<endl;
}
return 0;
}
B. Array Decrements
算出ai-bi的值,然后判断一遍,
WA:存在ai(ai>0)的值不变且其他ai变为0的情况
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define NOTLE ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'
#define T int TT;cin >> TT;while (TT--)
#define lint long long
#define pb push_back
#define eb emplace_back
int a[50010],b[50010],c[50010];
int main(){
NOTLE;
T{
int n,f=1,m=-1,ma=0;
cin >> n;
for(int i=1;i<=n;++i) cin >> a[i];
for(int i=1;i<=n;++i){
cin >> b[i];
c[i]=a[i]-b[i];
if(c[i]<0) f=0;
if(b[i]==0) ma=max(c[i],ma);
if(b[i]!=0) m=c[i];
}
for(int i=1;i<=n;i++){
if(c[i]!=m && b[i]!=0) f=0;
if(b[i]!=0 && c[i]<ma) f=0;
if(!f) break;
}
if(f) cout << "YES" << endl;
else cout << "NO" <<endl;
}
return 0;
}
C. Restoring the Duration of Tasks
C - Restoring the Duration of Tasks
直接判断任务开始时间和上一个任务结束时间的关系就行
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define NOTLE ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'
#define T int TT;cin >> TT;while (TT--)
#define lint long long
#define pb push_back
#define eb emplace_back
int s[500010],f[500010],ans[500010];
int main(){
NOTLE;
s[0]=0;
f[0]=0;
T{
int n;
cin >> n;
for(int i=1;i<=n;++i) cin >> s[i];
for(int i=1;i<=n;++i){
cin >> f[i];
if(s[i]>=f[i-1]) ans[i]=f[i]-s[i];
else ans[i]=f[i]-f[i-1];
cout << ans[i] << ' ';
}
cout << endl;
}
return 0;
}
D. Black and White Stripe
算前缀和来找一段固定长度区间的最大值
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define NOTLE ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'
#define T int TT;cin >> TT;while (TT--)
#define lint long long
#define pb push_back
#define eb emplace_back
int a[500010],d[500010];
int main(){
NOTLE;
a[0]=0;
d[0]=0;
T{
int n,k,ans=0;
cin >> n >> k;
for(int i=1;i<=n;++i){
char c;
cin >> c;
if(c=='W') a[i]=0;
else a[i]=1;
d[i]=d[i-1]+a[i];
if(i>=k) ans=max(d[i]-d[i-k],ans);
}
cout << k-ans << endl;
}
return 0;
}
E. Price Maximization
贪心,
WA:在用完之前剩下的小余数和大余数时忘记清空了
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define NOTLE ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'
#define T int TT;cin >> TT;while (TT--)
#define lint long long
#define pb push_back
#define eb emplace_back
lint a[500010],m[1010];
int main(){
NOTLE;
T{
//mas记录大于等于k/2的余数数量,mis则记录剩下的小余数数量
lint n,k,ans=0,mas=0,mis=0;
cin >> n >> k;
memset(m,0,sizeof(m));
for(int i=1;i<=n;++i){
cin >> a[i];
++m[a[i]%k];
ans+=a[i]/k;
}
for(int i=k/2;i>=1;i--){
if(k-i==i) ans+=m[i]/2,mas+=m[i]%2;
else{
if(m[i]>=m[k-i]){
ans+=min(m[i],m[k-i]);
mis+=m[i]-m[k-i];
}
if(m[i]<m[k-i]){
ans+=min(m[i]+mas+mis,m[k-i]);
if(m[i]+mis>=m[k-i]) mis=m[i]+mis-m[k-i];
else if(m[i]+mis+mas>=m[k-i]) mas=m[i]+mis+mas-m[k-i],mis=0;
else mas=m[k-i]-(m[i]+mis+mas),mis=0;
}
}
}
ans+=mas/2;
cout << ans << endl;
}
return 0;
}
边栏推荐
- 2022-2028 investigation and trend analysis report on global anti UAV netting gun industry
- At time_ What happens to TCP connections in wait status after SYN is received?
- CV学习笔记-CNN-VGG
- mysql 往字段后面加字符串
- IELTS review 1
- Dbutil auxiliary class, manual commit transaction, metadata
- Market Research - current situation and future development trend of Brazil berry oil market in the world and China
- Could not find artifact com.retail.stock:retail-stock-center:pom:1.0-SNAPSHOT in snapshots
- Report on Market Research and future forecast of Chinese pharmaceutical rubber stopper (2022 Edition)
- Market Research - current market situation and future development trend of polyol preservatives in the world and China
猜你喜欢

Clickhouse distributed table & local table & Clickhouse realize time series data management and mining

Senior management information systems and data warehouses and external / unstructured data and data warehouses

【读点论文】Benchmark Analysis of Representative Deep Neural Network Architectures当准确率不再是唯一衡量标准,给多目标优化一个导向

Summary of MySQL knowledge points

Will ebpf be the future of service grid?

【读点论文】GhostNet: More Features from Cheap Operations 卷积操作还是比较昂贵,特征图冗余可以线性变换获得

CV learning notes cnn-vgg

MySQL common interview knowledge points

CV学习笔记-CNN-VGG

ELK+Filebeat 部署安装
随机推荐
PHP get last Monday, get the last week date of the specified date, last Monday
2022-2028 investigation and trend analysis report on global anti UAV netting gun industry
Leetcode: find the number of recent palindromes
Laravel cross database query
Redis---07---basic command operations of redis (mainly about how to expand the struct and map of go into redis parameters, and how to use struct to obtain the key value batch array returned by redis)
MySQL查询数据库所有表名及其注释
leetcodeSQL:1070. Product sales analysis III
[penetration test] summary of conditional competition vulnerabilities
Summary of MySQL knowledge points
自制编译器学习4:使用Flex
Market Research - current market situation and future development trend of polyol preservatives in the world and China
Elk cluster settings account password authentication
Dbutil auxiliary class, manual commit transaction, metadata
3D编程模式:依赖隔离模式
自制编译器学习2:编译的过程
集成电路设计开源EDA软件yosys详解1:工具安装
Market Research - current situation and future development trend of global and Chinese sunfish feed market
ELK+Filebeat 部署安装
AMS advanced - how to start an unregistered activity
国信证券开户安全吗