当前位置:网站首页>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;
}
边栏推荐
- 原创翻译 | 机器学习模型服务工具对比:KServe,Seldon Core和BentoML
- Navicat premium connection problem --- host 'XXXXXXXX' is not allowed to connect to this MySQL server
- Leetcode 989. Integer addition in array form (simple)
- Original translation | comparison of machine learning model service tools: kserve, Seldon core and bentoml
- Leetcode 821. Minimum distance of characters (simple) - sequel
- MySQL Express - day 1 - basic introduction
- 释放开源数据库创新力量 | 【甘肃】openGauss Meetup圆满结束
- oss上传调用的是哪个方法
- GoLand永久激活
- Unity3D Button根据文本内容自适应大小
猜你喜欢

Implementation string mystring

squid代理服務器

VMware vSphere ESXi 7.0安装教程

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

KDD 2022 | 图“预训练、提示、微调”范式下的图神经网络泛化框架

银河麒麟系统局域网文件共享教程

Industry case | see the operation of bank digital transformation from the king of retail

送你12个常用函数公式,用过的都说好

行业案例|从零售之王看银行数字化转型的运营之道

How to do a good job of gateway high availability protection in the big promotion scenario
随机推荐
Leetcode 821. Minimum distance of characters (simple) - sequel
华为伙伴暨开发者大会2022开源时刻全纪录
GFS分布式文件系统
Cortical traceability analysis of ERP
Implementation string mystring
2021全球独角兽榜发布:中国301家独角兽企业全名单来了!
Ceph分布式存储
[STL programming] [common competition] [Part 3]
分享下我是如何做笔记的
NVIDIA three piece environment configuration
爱数课实验 | 第六期-金融反欺诈案例研究
MYSQL 性能优化 index 函数,隐藏,前缀,hash 索引 使用方法(2)
Openharmony hisysevent dotting and calling practice of # Summer Challenge (L2)
squid代理服务器
MySQL速成——第一天--基础入门
A distribution fission activity is more than just a circle of friends
抖音的兴趣电商已经碰到流量天花板?
Abap-sm30 check before deletion
Covering access to 2w+ traffic monitoring equipment, EMQ creates a new digital engine for all elements of traffic in Shenzhen
Here are 12 commonly used function formulas for you. All used ones are good