当前位置:网站首页>Codeforces Round #721 (Div. 2)
Codeforces Round #721 (Div. 2)
2022-06-27 22:04:00 【My story was traded for wine】
2021.5.20
A
The question : Give an integer n, Find the largest k, among n&(n-1)&...&k=0
Answer key : Just need to make n Every decreasing number, every binary bit, exists 0, May think k Namely n The highest position of 1 The others are 0 Number of numbers m-1, This ensures that every binary bit has 0
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
ll t,n;
cin>>t;
while(t--)
{
cin>>n;
if(n==1)
cout<<0<<endl;
else if(n==2)
cout<<1<<endl;
else{
ll k=1;
while(k<n){
k*=2;
}
if(k!=n)
k/=2;
cout<<k-1<<endl;
}
}
return 0;
}
B1
The question : The rules : There can only be two operations at a time :1、 hold 0 become 1 cost 1 ;2、 If the status of the current string is not palindrome string , That can reverse the string of subsymbols , If it is a palindrome string or the previous round used flipping , You can only use the operation 1, Can't flip . Give a palindrome string , Contains only 0 and 1,ALICE First of all ,BOB Later stage , Finally, the strings are changed to 1 Who spends more , If so, output “DRAW”.
Answer key : Just judge the substring 0 The number of , If there is no 0 It must be a draw , If 0 The number of is odd , Then prove that the length of the string is odd , And the middle one is 0, If only 1 individual 0 Then you must lose first , If it is greater than 1, Then the back hand will lose ( such as “10001”, Take off the middle first , String is palindrome again , The back hand can only take the cost 1, Then turn it over first , The second hand can only spend 1), If 0 The number of is even , Then the first hand will lose .( Finally, there are two forerunners left, and each time they have to spend 1, Backhand flip , The last one can only be spent first 1)
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
int t,n;
string s;
cin>>t;
while(t--)
{
cin>>n>>s;
int k0=0,k1=0,len=s.size();
for(int i=0;i<n;i++)
{
if(s[i]=='0')
k0++;
else
k1++;
}
if(k0==0)
cout<<"DRAW"<<endl;
else
{
if(k0%2)
{
if(k0==1)
cout<<"BOB"<<endl;
else
cout<<"ALICE"<<endl;
}
else
{
cout<<"BOB"<<endl;
}
}
}
return 0;
}B2
The question : Again B1 On the basis of , The input substring is not necessarily a palindrome string .
Answer key : It is only necessary to point out that it is not a case of winning first :0 The number is 2 And there is only one asymmetric position , It was a draw , If it is a palindrome string and 0 The number of is even or 0 The number of 1, Then the backhand wins , In other cases, we win first ( There is a choice of holding or turning first , So you can get rid of losing , Give yourself the loss to the latter )
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <string>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
int t,n;
string s;
cin>>t;
while(t--)
{
cin>>n>>s;
int dif=0;
for(int i=0;i<(n+1)/2;i++)
{
if(s[i]!=s[n-i-1])
dif++;
}
int num=count(s.begin(),s.end(),'0');
if(!dif&&(num%2==0||num==1))
cout<<"BOB"<<endl;
else if(dif==1&&num==2)
cout<<"DRAW"<<endl;
else
cout<<"ALICE"<<endl;
}
return 0;
}C
The question : Give a length of n Integer sequence of a, Where if an integer pair i<j && ai=aj Then the contribution of this integer pair is 1, If different subsequences have repeated positional contributions, they belong to different contributions , Calculation sequence a The contribution sum of all subsequences of .
Answer key :dp[i] The contribution of =dp[i-1] The contribution of + contain ai The contribution of subsequences of this number ( All the preceding is equal to ai The subscript sum of the number of * Included later ai A few more numbers can be used as subsequences )
#include <iostream>
#include <algorithm>
#include <map>
#define ll long long
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
int t,n,x;
cin>>t;
while(t--)
{
cin>>n;
map<int,ll>m;
ll sum=0;
for(int i=1;i<=n;i++)
{
cin>>x;
sum+=m[x]*(n-i+1);
cout<<m[x]*(n-i+1)<<endl;
m[x]+=i;
}
cout<<sum<<endl;
}
return 0;
}
边栏推荐
- Common problems encountered by burp Suite
- 熊市慢慢,Bit.Store提供稳定Staking产品助你穿越牛熊
- Installing Oracle11g under Linux
- matlab查找某一行或者某一列在矩阵中的位置
- Go 访问GBase 8a 数据库的一个方法
- Special tutorial - Captain selection game
- [LeetCode]动态规划解拆分整数I[Silver Fox]
- Luogu p5706 redistributing fertilizer and house water
- [leetcode] dynamic programming solution partition array ii[arctic fox]
- Quick excel export
猜你喜欢

Management system itclub (Part 2)

YOLOv6:又快又准的目标检测框架开源啦

Simulink导出FMU模型文件方法

"Apprendre cette image" apparaît sur le Bureau win11 comment supprimer

Go from introduction to actual combat -- channel closing and broadcasting (notes)

Knowledge sorting of exception handling

清华大学教授:软件测试已经走入一个误区——“非代码不可”

Read write separation master-slave replication of MySQL

美团20k软件测试工程师的经验分享

JVM memory structure when creating objects
随机推荐
Installing Oracle11g under Linux
Summary of gbase 8A database user password security related parameters
Knowledge sorting of exception handling
Stm32cubeide1.9.0\stm32cubemx 6.5 f429igt6 plus lan8720a, configure eth+lwip
vmware虚拟机PE启动
win11桌面出現“了解此圖片”如何删除
Method of reading file contents by Excel
STM32CubeIDE1.9.0\STM32CubeMX 6.5 F429IGT6加LAN8720A,配置ETH+LWIP
List of language weaknesses --cwe, a website worth learning
[LeetCode]100. Same tree
[LeetCode]572. 另一棵树的子树
MONTHS_BETWEEN函数使用
开源技术交流丨一站式全自动化运维管家ChengYing入门介绍
熊市慢慢,Bit.Store提供稳定Staking产品助你穿越牛熊
GBase 8a OLAP分析函数 cume_dist的使用样例
Interview question 3 of software test commonly used by large factories (with answers)
Go from introduction to actual combat - only any task is required to complete (notes)
Go from introduction to practice -- definition and implementation of behavior (notes)
正则表达式
MYSQL和MongoDB的分析