当前位置:网站首页>Codeforces Round #797 (Div. 3) A—E
Codeforces Round #797 (Div. 3) A—E
2022-07-02 06:22:00 【I cried at the sound of wa】
First put a roast after the day's typing :
today cf It's disgusting , First card b Card for dozens of minutes , Finish and then quickly c Then I got stuck d, I really can't think of it, so I went to write e, Over e Find out e Over 2000 people d Over 7000 people , Gray continue to write d, The result prefix and are over , Give me disgusting , Fortunately, so many people I've seen didn't think dp, Or send it directly .
A. Print a Pedestal (Codeforces logo?)
A brief explanation of the meaning of the topic
#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
The question :
Each operation can make all the numbers -1, If it changes to 0 Then it will not be reduced .
Answer key :
Except for returnable 0 Directly calculate the difference of , All differences are required to be equal , return 0 The difference of is less than or equal to the difference that requires identity .
wa: card b Not because it's hard to think , I made the difference in the first position , Forget that the first position is return 0 Can not be used as a reference . We need to judge the real 【 Difference value 】.
#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
A brief explanation of the meaning of the topic
notes : According to the conditions, we know that there is no existence. The previous one is not over, but the next one is over , And I wrote one more in consideration of this situation max, Deletion has no effect .
#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
The question :
Select the minimum number of dyes to make it grow to k The subsequence of is all black .
Answer key :
Personal thinking :
At first glance, it seems that some algorithms should be used , however div3(), There are many people . It belongs to pure thinking , And fear is dp. I can't think of a pure thinking solution , Not willing to use Algorithm , So kazhi .
In fact, just use the prefix and slightly optimize the direct violence , We directly calculate the length of all intervals as k The subsequence —> Calculate all the staining possibilities , Take the minimum .
#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
The question :
At first sight : The title is long and rounded down , It must be a difficult math problem !( A fart )
In fact, the feeling and D Almost difficult :n Number , Add two and divide by k( Rounding down ), How to maximize the answer ?
Answer key :
Put all the ‘k’ Take it out first . This will not be lost by rounding down 1, Add all and save ans.
Deal with the rest , In fact, it is the remainder ,sort Take the sequence . Double pointer traversal guarantees maximum , See code for this part , When the sum of two numbers is greater than k Then you can ans++.
final ans That's the answer. .
Not open ll wa A hair ()
#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;
}
边栏推荐
- LeetCode 39. 组合总和
- The Chinese word segmentation task is realized by using traditional methods (n-gram, HMM, etc.), neural network methods (CNN, LSTM, etc.) and pre training methods (Bert, etc.)
- When requesting resttemplate, set the request header, request parameters, and request body.
- 数据科学【九】:SVD(二)
- Spark overview
- Google Play Academy 组队 PK 赛,正式开赛!
- Google play academy team PK competition, official start!
- 加密压缩文件解密技巧
- Step by step | help you easily submit Google play data security form
- 深入学习JVM底层(五):类加载机制
猜你喜欢

TensorRT的数据格式定义详解

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

Amazon AWS data Lake Work Pit 1

Linear DP (split)

The official zero foundation introduction jetpack compose Chinese course is coming!

注解和反射详解以及运用

LeetCode 90. 子集 II

Deep learning classification network -- Network in network

Common means of modeling: combination

Leverage Google cloud infrastructure and landing area to build enterprise level cloud native excellent operation capability
随机推荐
官方零基础入门 Jetpack Compose 的中文课程来啦!
LeetCode 83. Delete duplicate elements in the sorting linked list
Summary of WLAN related knowledge points
VLAN experiment of switching technology
最新CUDA环境配置(Win10 + CUDA 11.6 + VS2019)
TensorRT的命令行程序
LeetCode 47. Full arrangement II
Decryption skills of encrypted compressed files
LeetCode 40. 组合总和 II
CUDA与Direct3D 一致性
Detailed notes of ES6
LeetCode 90. 子集 II
CUDA中的函数执行空间说明符
TensorRT的数据格式定义详解
LeetCode 90. Subset II
程序员的自我修养—找工作反思篇
日期时间API详解
Detailed explanation of BGP message
BGP中的状态机
Database learning summary 5