当前位置:网站首页>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;
}
边栏推荐
- Deep learning classification network -- Network in network
- Arduino Wire 库使用
- Flutter hybrid development: develop a simple quick start framework | developers say · dtalk
- 标签属性disabled selected checked等布尔类型赋值不生效?
- Spark overview
- Lucene Basics
- 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.)
- Singleton mode compilation
- 复杂 json数据 js前台解析 详细步骤《案例:一》
- Style modification of Mui bottom navigation
猜你喜欢

Invalid operation: Load into table ‘sources_ orderdata‘ failed. Check ‘stl_ load_ errors‘ system table

Zhuanzhuanben - LAN construction - Notes

浏览器原理思维导图

Linear DP (split)

Amazon AWS data Lake Work Pit 1

深入学习JVM底层(四):类文件结构

稀疏数组(非线性结构)

Contest3147 - game 38 of 2021 Freshmen's personal training match_ E: Listen to songs and know music

WLAN相关知识点总结

500. Keyboard line
随机推荐
Sentinel规则持久化到Nacos
Detailed notes of ES6
Deep learning classification network -- Network in network
Format check JS
Step by step | help you easily submit Google play data security form
栈(线性结构)
Eco express micro engine system has supported one click deployment to cloud hosting
CUDA与Direct3D 一致性
一起学习SQL中各种join以及它们的区别
网络相关知识(硬件工程师)
Golang -- map capacity expansion mechanism (including source code)
Summary of WLAN related knowledge points
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?
Google Go to sea entrepreneurship accelerator registration countdown 3 days, entrepreneurs pass through the guide in advance collection!
Leverage Google cloud infrastructure and landing area to build enterprise level cloud native excellent operation capability
Decryption skills of encrypted compressed files
递归(迷宫问题、8皇后问题)
LeetCode 283. 移动零
On Web server
WLAN相关知识点总结