当前位置:网站首页>Codeforces round 784 (Div. 4) AK solution
Codeforces round 784 (Div. 4) AK solution
2022-04-22 17:58:00 【CCSU_ Plum wine】
A little memory of the first time ak cf div4 ( Although it's very simple , But it is said that CF Only once before div4 Ash is often rare )
link :Round #784 (Div. 4)
Codeforces Round #784 div.4
A Division?
The title gives the corresponding rank of different scores if Just judge the output of the statement
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
void solve()
{
int n;
cin >> n;
if(n >= 1900)cout << "Division 1"<<endl;
else if(1600<=n && n<=1899)cout << "Division 2"<<endl;
else if(1400<=n && n<=1599)cout << "Division 3"<<endl;
else if(n <=1399)cout << "Division 4"<<endl;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)solve();
return 0;
}
B Triple
Given length is n n n Array of a i ai ai Ask whether there is a number in the array, and the number of occurrences is greater than or equal to 3, Because the number is very small a i < n ai < n ai<n So we use vis The number of array tags is enough The subscript represents the value . If it does not exist ai Size limit for We can use map The recording effect is the same
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
int vis[N];
void solve()
{
int n;
cin >> n;
int ans = -1;
for(int i=1;i<=n;i++)vis[i] = 0;
for(int i=1;i<=n;i++)
{
int x;
cin >> x;
vis[x] ++;
if(vis[x] >= 3)ans = x;
}
cout << ans << endl;
return ;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)solve();
return 0;
}
C Odd/Even Increments
The question :
Given length is n n n Array of You can add... To all numbers with even or odd subscripts 1 There is no limit to the number of operations Ask if all the odd and even numbers in the array can be made one .
Ideas :
because Each operation must be performed on all even or odd subscripts , For all numbers with the same subscript parity, each change is synchronous , If the initial is different, it is impossible to make it the same by operation . for example :1 2 2 Subscript to be 1 3 The initial parity of the number is different , Operate on even subscripts 1 3 Subscripts have no effect , The operation of odd subscript can only change parity at the same time . So judge whether the initial array has odd subscripts / Whether even subscripts and parity are the same .
CODE:
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
const int N = 110;
int a[N];
void solve()
{
int n;
cin >> n;
bool F = true;
for(int i=1;i<=n;i++)
{
cin >> a[i];
if((i&1)&&a[i]%2!=a[1]%2)F = false;
else if(i%2==0 && a[i]%2!=a[2]%2)F = false ;
}
if(F) cout << "YES" << endl;
else cout << "NO" << endl;
return ;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)solve();
return 0;
}
D Colorful Stamp
The question :
Given length is n n n String There is only ′ R ′ 'R' ′R′ Red ′ B ′ 'B' ′B′ Blue ′ W ′ 'W' ′W′ Three white characters , Now I'll give you a length of n n n All characters of the are W W W String . You have an unlimited number of operations , The selected subscript is i , i + 1 i ,i+1 i,i+1 Change the character of to R B RB RB perhaps B R BR BR You can repeat the operation on the same character , Subscript selection : 1 ≤ i < n 1≤i<n 1≤i<n. Ask if you can do several operations to change the string to a given string
Ideas :
First of all, we can get from the question : To be W W W Separated substrings can be judged separately , because W W W Cannot be altered by staining , All of them have no influence on each other for example :WRRBWBBRW Two separated substrings RRB and BBR They don't influence each other . Next, we'll discuss it according to the situation :
1. For length is 1 String And the only character is R R R or B B B It must be impossible to get , So we can deduce a separate substring ( By W W W Separated substrings ) If its color is solid and not white Then the substring must not be obtained for example WBBW,WRR.
2. For non pure colors ( That is, a separate substring contains both B B B Contain, R R R) Let's make a conclusion first It must be possible to do several operations to get , prove : For adjacent characters, there is no substring of the same character ( That is, the adjacent blue must be red , vice versa ) Come on We can use the basic operation ( B R BR BR, R B RB RB) To get W W W WWW WWW -> W R B WRB WRB -> B R B BRB BRB.
For substrings with equal adjacent characters It can also be obtained by the following operations W W W WWW WWW -> W R B WRB WRB -> R R B RRB RRB, R B B RBB RBB, B B R BBR BBR, B R R BRR BRR So it is with . So we can construct all substrings .
The code is very simple , For individual substrings, calculate R,B The number of If a color is 0 One is not 0 It indicates that the substring is a non white solid color substring Direct output NO that will do
CODE
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
const int N = 1e5 + 10;
char a[N];
void solve()
{
int n;
cin >> n;
cin >> (a + 1);
int sum1=0,sum2=0;
for(int i=1;i<=n;i++)
{
if(a[i] == 'R')sum1 ++;
else if(a[i] == 'B')sum2 ++;
if(a[i]=='W' || i==n)
{
if((sum1&&!sum2)||(!sum1&&sum2))
{
cout << "NO" << endl;
return ;
}
sum1 = 0;
sum2 = 0;
}
}
cout << "YES" <<endl;
return ;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)solve();
return 0;
}
E 2-Letter Strings
The question :
Given n n n A length of 2 String , Ask how many string pairs there are ( i , j ) i < j (i,j) i<j (i,j)i<j Satisfy i String and j The string has one and only one character different .
Ideas :
Because the string length is only two digits, we use s 1 s1 s1 s 2 s2 s2 Represents these two characters , use c n t 1 , c n t 2 cnt1,cnt2 cnt1,cnt2 The array records the first character as s 1 s1 s1 The second character of the string is s 2 s2 s2 The number of strings .
So for i i i character string : c h 1 , c h 2 ch1,ch2 ch1,ch2 The contribution of is to add the first character and c h 2 ch2 ch2 The same and the second character is the same as c h 2 ch2 ch2 Same number of strings , Finally, it happens to be c h 1 c h 2 ch1ch2 ch1ch2 The number of strings . Because the number of strings that exactly equal when the first character is the same and the second character is the same is calculated once , So the last minus is multiplied by 2. It happens to be c h 1 c h 2 ch1ch2 ch1ch2 The number of strings we can use map Statistics . therefore a n s = c n t 1 [ c h 1 − ′ a ′ ] + c n t 2 [ c h 2 − ′ a ′ ] − 2 ∗ m a p [ c h 1 , c h 2 ] ; ans = cnt1[ch1-'a'] + cnt2[ch2-'a'] - 2 * map[{ch1,ch2}]; ans=cnt1[ch1−′a′]+cnt2[ch2−′a′]−2∗map[ch1,ch2];, Every time I traverse i The postscript will i The count of strings starts from cnt1 In the from cnt2 To prevent double counting ( i , j ) i > = j Of love condition (i,j)i>=j The situation of (i,j)i>=j Of love condition . Example :
n = 6
1.ac
2.ac
3.ak
4.ak
5.bc
6.bc
about 1.ac The first character is a The string of is 1,2,3,4 common 4 The second character is c There are 1,2,5,6 common 4 individual
Both are right 1,2 ac Statistics were made, and finally ans = 4 + 4 - 2 * 2
CODE
#include<map>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
const int N = 1e5 + 10;
ll s1[30],s2[30];
char ch1[N],ch2[N];
map<pair<char,char>,ll>mp;
void solve()
{
int n;
cin >> n;
mp.clear();
for(int i=1;i<=n;i++)
{
cin >> ch1[i] >> ch2[i];
s1[ch1[i]-'a'] ++;
s2[ch2[i]-'a'] ++;
mp[{
ch1[i],ch2[i]}] ++;
}
ll ans = 0;
for(int i=1;i<=n;i++)
{
ll sum = s1[ch1[i]-'a'] + s2[ch2[i]-'a'] - 2 * mp[{
ch1[i],ch2[i]}];
ans += sum;
s1[ch1[i]-'a'] --;
s2[ch2[i]-'a'] --;
mp[{
ch1[i],ch2[i]}] --;
}
cout << ans << endl;
return ;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)solve();
return 0;
}
F Eating Candies
The question :
Given n n n A candy weighs a i ai ai A Only eat from left to right ,B You can only eat from right to left , And you can't skip not eating the current candy to eat the later . requirement A and B The weight of candy is the same , Ask how much candy they can eat at most .
Ideas :
You can only eat candy in one direction , And requiring equal weight, we thought of using the prefix and . use map Record A The historical prefix of and the subscript of are S 1 − > S n S1 ->Sn S1−>Sn, Then find out from the back to the front B And For each S i Si Si stay map Query in If there are equal , And the query found A Prefix and location of i d < i id < i id<i Then you can update the answer .
for example :
6
2 1 4 2 4 1
map As recorded in
2 3 7 9 13 14 Left to right prefixes and
1 2 3 4 5 6 Prefix and corresponding number
Find the prefix sum from right to left
1 5 7 11 12 14
-1 -1 3 -1 -1 -1 map The number recorded in Only 7 Found the corresponding answer ans = 3 + n - 3 + 1
CODE
#include<map>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
int a[N];
map<ll,int>mp;
void solve()
{
int n;
cin >> n;
mp.clear();
ll sum1=0,sum2=0,ans=0;
for(int i=1;i<=n;i++)
{
cin >> a[i];
sum1 += a[i];
mp[sum1] = i;
}
int id;
for(int i=n;i>=1;i--)
{
sum2 += a[i];
if(mp.count(sum2))id = mp[sum2];
else continue ;
if(id < i)ans = id + n - i + 1;
else break;
}
cout << ans << endl;
return ;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)solve();
return 0;
}
G Fall Down
Simulate the process of stone falling , Because columns do not affect each other We can simulate each column separately
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
const int N = 110;
char a[N][N];
void solve()
{
int n,m;
cin >> n >> m;
for(int i=1;i<=n;i++)scanf("%s",a[i] + 1);
for(int i=1;i<=m;i++)// Start with the column
{
for(int j=n,up=j;j>=1;up=j,j--)
{
if(a[j][i]=='o') continue ;
int sum = 0;
up = j;
if(a[j][i]=='*')sum = 1;
while(up - 1 >= 1 && a[up - 1][i]!='o')
{
up --;
if(a[up][i]=='*')sum ++;
}
for(int k=0;k<sum;k++) a[j-k][i] = '*';
for(int k=j-sum;k>=up;k--) a[k][i] = '.';
j = up;
}
}
for(int i=1;i<=n;i++)printf("%s\n",a[i] + 1);
return ;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)solve();
return 0;
}
H Maximal AND
The question :
It's classic cf Bit operation problem , Given length is n n n Array of a a a Yes k k k It's an opportunity . Can make any a i ∣ 2 j ( j < = 30 ) ai | 2^j(j<=30) ai∣2j(j<=30) Ask for k After this operation, it will a 1 A N D a 2 A N D … A N D a n a1 AND a2 AND … AND an a1ANDa2AND…ANDan What is the maximum value after .
Ideas :
Because binary numbers A N D AND AND The operation of different digits has no effect , The final answer is binary if 1 All required a i ai ai The binary digit is 1 So we greedily start traversing the array from the high bit of binary , if a i ai ai This position is 0 So count s u m + + sum ++ sum++ take a 1 − > a n a1->an a1−>an If less than or equal to... After statistics k k k It shows that the binary digit can make all... Through several operations a i ai ai by 1 The answer plus the value represented by the binary digit , meanwhile k − s u m k - sum k−sum
CODE
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
ll a[N],b[40],n,k;
void init()
{
b[0] = 1;
for(int i=1;i<=30;i++)b[i] = b[i-1] << 1;// Preprocess the value of binary digits
}
void solve()
{
cin >> n >> k;
for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
ll ans = 0;
for(int i=30;i>=0;i--)
{
int sum = 0;
for(int j=1;j<=n;j++)
{
if(!(a[j]>>i&1)) sum ++;// Bit operation determines whether the binary digit on this bit is 1
}
if(k >= sum)
{
ans += b[i];
k -= sum;
}
}
printf("%lld\n",ans);
return ;
}
int main()
{
int T;
init();
scanf("%d",&T);
while(T--)solve();
return 0;
}
summary
The problem is not difficult , No, the algorithms are basically simple simulation and thinking to find rules . It should be E,H It's a little difficult . Generally speaking, it can be half an hour in advance AK ok , Hand speed and thinking are still a little slow ,rk1 Big guy is so strong , One question per minute on average 12 The speed of light per minute AK tql%%%.
版权声明
本文为[CCSU_ Plum wine]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221754571771.html
边栏推荐
- Soft test advanced item notes | software integration technology
- Common error reporting records
- The security configuration method of remote terminal service (3389) does not need public network IP, and realizes external network access to remote desktop in three steps
- [Lane] ultra fast lane detection (2) custom model test
- 嵌入式设计与开发项目-数码管静态显示程序设计
- National Information Exchange Model(NIEM)操作手册
- Spacy first routine (automatic annotation of Chinese text)
- Spacy tutorial learning
- 【Lane】Ultra-Fast-Lane-Detection(1)自定义数据集训练
- Activiti suspend and activate tasks
猜你喜欢

软考高项笔记 | 信息系统项目典型生命周期模型

National Information Exchange Model(NIEM)操作手册

Soft test high-level notes | tools and techniques for collecting needs

软考高项笔记 | 项目的特点

Soft test high item notes | contents of project proposal

National information exchange model (NIEM) operation manual

软考高项笔记 | 项目管理知识体系构成

Activiti suspend and activate tasks

优麒麟 22.04 LTS 版本正式发布 | UKUI 3.1开启全新体验!

Configuring test libraries for JUnit
随机推荐
微软测试人员简述
Soft test advanced item notes | software integration technology
R3live笔记:从代码看lio线程
嵌入式设计与开发项目-数码管静态显示程序设计
An understanding process and its communication method
为什么智能手机传感器市场一直是索尼占主导
rm格式的文件怎么打开?
【C语言进阶篇】一篇文章带你认清结构、枚举和联合
With the increasing abundance of e-book products, iFLYTEK intelligent office book is still an ideal choice
CISP examination resource sharing
es6 Generator函数的使用
广东水泥数据概况
Huawei router realizes the connection between headquarters and branches through MPLS virtual private network
你知道你的手机上有多少传感器吗?
【Lane】Ultra-Fast-Lane-Detection(2)自定义模型测试
Multithreaded notes | future interface function
Why has Sony always dominated the smartphone sensor market
dpdk从给定的port/queue捕获流量
小程序----API
电脑上怎么快速切换显示不同的软件界面