当前位置:网站首页>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;
}
边栏推荐
- 正则表达式
- BAT测试专家对web测试和APP测试的总结
- Express e stack - small items in array
- Experience sharing of meituan 20K Software Test Engineers
- QT base64 encryption and decryption
- Management system itclub (Part 2)
- JVM memory structure when creating objects
- VMware virtual machine PE startup
- [leetcode] dynamic programming solution split integer i[silver fox]
- Simulink method for exporting FMU model files
猜你喜欢

At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions

Secret script of test case design without leakage -- module test

Process control task

Bit.Store:熊市漫漫,稳定Staking产品或成主旋律

深度学习又有新坑了!悉尼大学提出全新跨模态任务,用文本指导图像进行抠图

Set code exercise

AQS SOS AQS with me

Slow bear market, bit Store provides stable stacking products to help you cross the bull and bear

真香,自从用了Charles,Fiddler已经被我彻底卸载了

Null pointer exception
随机推荐
分享|智慧环保-生态文明信息化解决方案(附PDF)
Have time to look at ognl expressions
List of language weaknesses --cwe, a website worth learning
[MySQL] database function clearance Tutorial Part 2 (window function topic)
[LeetCode]515. 在每个树行中找最大值
Go from introduction to actual combat - task cancellation (note)
vmware虚拟机PE启动
【Redis】零基础十分钟学会Redis
Summary of gbase 8A database user password security related parameters
The create database of gbase 8A takes a long time to query and is suspected to be stuck
Sharing | intelligent environmental protection - ecological civilization informatization solution (PDF attached)
Xiao Wang's interview training task
At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions
I think I should start writing my own blog.
Common problems encountered by burp Suite
Secret script of test case design without leakage -- module test
Example of using gbase 8A OLAP function group by grouping sets
年薪50W+的测试大鸟都在用这个:Jmeter 脚本开发之——扩展函数
熊市慢慢,Bit.Store提供稳定Staking产品助你穿越牛熊
TreeSet details