当前位置:网站首页>Codeforces Round #721 (Div. 2)
Codeforces Round #721 (Div. 2)
2022-06-27 19:14:00 【我的故事用酒换】
2021.5.20
A
题意:给一个整数n,求出最大的k,其中n&(n-1)&...&k=0
题解:只需要让n每次递减的数每个二进制位都有存在0,可想k就是n的最高位为1其他位都为0的数m-1,这样可以保证每位二进制位都有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
题意:规则:每次只能有两个操作:1、把0变成1花费1 ;2、若现在字符串的状态不为回文串,那可以把子符串颠倒,若为回文串或者上一回合用了翻转,则只能用操作1,不能翻转。给一个回文字符串,只包含0和1,ALICE先手,BOB后手,最后把字符串都变为1谁花费的多,一样的话输出“DRAW”。
题解:只需判断子串串0的个数,若无0肯定就是平局,如果0的个数为奇数,那么证明字符串长度为奇数,且最中间的为0,这种情况如果只有1个0那么肯定是先手输,如果大于1,则后手必输(比如“10001”,先手拿掉中间的,字符串又是回文,后手只能拿花费1,然后先手翻转,后手又只能花1),如果0的个数为偶数,那么先手必输。(最后剩两个先手每次必花费1,后手翻转,最后一个又只能先手花费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
题意:再B1的基础上,输入的子符串不一定是回文串。
题解:只需枚举出不是先手赢的情况:0个数为2且只有一个不对称的位置,一样是平局,如果是回文串且0的个数是偶数或者0的个数为1,那么就是后手赢,其他情况都是先手赢(先手有拿或者翻转的选择,所以可以去掉自己输的情况,把自己输的情况给后者)
#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
题意:给一个长度为n的整数序列a,其中若整数对 i<j && ai=aj 则这一整数对贡献为1,其中不同子序列若有重复的位置贡献属于不同的贡献,计算序列a的所有子序列的贡献和。
题解:dp[i]的贡献=dp[i-1]的贡献+包含ai这个数的子序列的贡献(前面所有等于ai的数的下标和*后面包含ai还要几个数可以作为子序列)
#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;
}
边栏推荐
- 抖音的兴趣电商已经碰到流量天花板?
- Safe and efficient, non-contact "hand brushing" identification helps epidemic prevention and control
- Best practice: optimizing Postgres query performance (Part 2)
- 送你12个常用函数公式,用过的都说好
- It took me 6 months to complete the excellent graduation project of undergraduate course. What have I done?
- Unleash the innovative power of open source database | [Gansu] opengauss meetup has come to a successful conclusion
- 关于企业数字化的展望(38/100)
- 基于微信小程序的高校党员之家服务管理系统系统小程序#毕业设计,党员,积极分子,学习,打卡,论坛
- 体验Navicat Premium 16,无限重置试用14天方法(附源码)
- How dbeaver restores and backs up databases
猜你喜欢

How dbeaver restores and backs up databases

Save method of JPA stepping pit series

MYSQL 性能优化 index 函数,隐藏,前缀,hash 索引 使用方法(2)
![[STL programming] [common competition] [Part 1]](/img/ce/4d489e62d6c8d16134262b65d4b0d9.png)
[STL programming] [common competition] [Part 1]

Focus! Tips for installing fonts on domestic computers

Flexible IP network test tool -- x-launch

抗洪救灾,共克时艰,城联优品驰援英德捐赠爱心物资

2021全球独角兽榜发布:中国301家独角兽企业全名单来了!

Ceph分布式存储

White whoring red team goby & POC, how do you call white whoring?
随机推荐
MYSQL 性能优化 index 函数,隐藏,前缀,hash 索引 使用方法(2)
Love math experiment | phase VI - Financial anti fraud case study
KDD 2022 | 图“预训练、提示、微调”范式下的图神经网络泛化框架
[STL programming] [common competition] [Part 3]
请教CMS小程序首页的幻灯片在哪里设置?
众昂矿业:新能源或成萤石最大应用领域
How to do a good job of gateway high availability protection in the big promotion scenario
安全高效,非接触“刷手”身份识别助力疫情防控
The meta universe virtual digital human is closer to us | Sinovel interaction
SQL必需掌握的100个重要知识点:IN 操作符
麒麟V10安装字体
VMware vSphere ESXi 7.0安装教程
SQL Server for循环用法
Tutorial | fNIRS data processing toolkit homer2 download and installation
Modify large online games through CE modifier
非常全面的DolphinScheduler(海豚调度)安装使用文档
How to reduce the weight transfer of unnecessary pages that users pay attention to?
Ceph分布式存储
GoLand permanently activated
BTC和ETH重新夺回失地!引领市场复苏?加密将步入“冰河时代”!