当前位置:网站首页>Codeforces Round #721 (Div. 2)B1. Palindrome Game (easy version)B2. Palindrome game (hard version)
Codeforces Round #721 (Div. 2)B1. Palindrome Game (easy version)B2. Palindrome game (hard version)
2022-07-01 04:13:00 【solemntee】
Look who is playing this autistic div.
Oh , It turned out to be me .
C It's too simple to say , Pay attention to discretization 1e9 The scope of the .
Let's see first e a s y easy easy v e r s i o n version version, The meaning of the title is to give you a palindrome string , You can do two things , Put one 0 become 1 Or skip this round ( If and only if the current is not a palindrome string ).
Easy to know, only with 0 The quantity is related to .
n = 1 , after hand win n=1, The backhand wins n=1, after hand win
n = p. Count n= Odd number n= p. Count
Because I know that the middle element is 0, Let's take the middle element first .
0001000 0001000 0001000
Then the second person can't flip , Because this time is palindrome string , No problem , We choose symmetrically with him .
0111220 0111220 0111220
In the last two, we flip
2111222 2111222 2111222
So when you know odd numbers, you will win first . And take the lead 1 Cost .
n = accidentally Count n= even numbers n= accidentally Count
Empathy , After the last round, turn your hands , The second is the winner . And the backhand is ahead 2 Cost .
Look again. h a r d hard hard v e r s i o n version version
Because this time is not a palindrome string , First, calculate the distance between the string and the palindrome string dis.
The first hand naturally leads the second dis Cost
When dis>2, Win first , Because the first hand is the worst 2 Cost
When dis=0, Back to the palindrome string
When dis=1, And there are only two 0 It ends in a draw
When dis=1, And there are more than two 0, Win first , Although in palindromes, we know that even numbers lead 2, But we can choose not to skip the last round , Exchange first, then hand
When dis=2, Because there is an operation of exchanging first and then , The first step is to win
Baby this inscription has been written for a long time , May be old crying crying
#include<bits/stdc++.h>
using namespace std;
int len;
char s[100005];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int cnt=0,cnt0=0;
scanf("%d",&len);
scanf("%s",s+1);
for(int i=1;i<=len;i++)if(s[i]=='1'&&s[len-i+1]=='0')cnt++;
for(int i=1;i<=len;i++)if(s[i]=='0')cnt0++;
if(cnt>2)printf("ALICE\n");
else
{
if(cnt==0)
{
cnt=cnt0;
if(cnt%2==1)
{
if(cnt==1)printf("BOB\n");
else printf("ALICE\n");
}
else printf("BOB\n");
}
else if(cnt==1)
{
cnt=cnt0-cnt;
if(cnt==0)printf("ALICE\n");
else if(cnt%2==1)
{
if(cnt==1)printf("DRAW\n");
else printf("ALICE\n");
}
else printf("ALICE\n");
}
else if(cnt==2)
{
cnt=cnt0-cnt;
if(cnt==0)printf("ALICE\n");
else if(cnt==1)printf("ALICE\n");
else if(cnt%2==1)printf("ALICE\n");
else printf("ALICE\n");
}
}
}
return 0;
}
边栏推荐
- [recommended algorithm] C interview question of a small factory
- 283. move zero
- Embedded System Development Notes 80: using QT designer to design the main interface
- Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)
- Common thread methods and daemon threads
- OSPF notes [multiple access, two multicast addresses with OSPF]
- “目标检测“+“视觉理解“实现对输入图像的理解
- What does ft mean in the data book table
- HoloLens2开发环境搭建及部署app
- LetCode 1829. Maximum XOR value per query
猜你喜欢
The problem of integrating Alibaba cloud SMS: non static methods cannot be referenced from the static context
NFT:使用 EIP-2981 开启 NFT 版税之旅
Coinbase in a bear market: losses, layoffs, stock price plunges
【TA-霜狼_may-《百人计划》】1.2.2 矩阵计算
Leetcode learning - day 36
Why can't you find the corresponding function by clicking go to definiton (super easy has a diagram)
206. reverse linked list
After many job hopping, the monthly salary is equal to the annual salary of old colleagues
[recommended algorithm] C interview question of a small factory
CF1638E colorful operations
随机推荐
The problem of integrating Alibaba cloud SMS: non static methods cannot be referenced from the static context
Network metering - application layer
[today in history] June 30: von Neumann published the first draft; The semiconductor war in the late 1990s; CBS acquires CNET
[EI conference] 2022 international joint civil and Offshore Engineering Conference (jccme 2022)
Libevent Library Learning
Use of JMeter counters
[human version] Web3 privacy game in the dark forest
Millet College wechat scanning code login process record and bug resolution
The programmer's girlfriend gave me a fatigue driving test
嵌入式系统开发笔记81:使用Dialog组件设计提示对话框
171. excel table column No
What does ft mean in the data book table
Usage of AfxMessageBox and MessageBox
[EI search] important information conference of the 6th International Conference on materials engineering and advanced manufacturing technology (meamt 2022) in 2022 website: www.meamt Org meeting time
30. Concatenate substrings of all words
Huawei simulator ENSP - hcip - Hybrid Experiment 2
PageObject模式解析及案例
Possible problems and solutions of using scroll view to implement slider view
Spock单元测试框架介绍及在美团优选的实践___第一章
DO280管理应用部署--RC