当前位置:网站首页>[sg function] 2021 Niuke winter vacation training camp 6 h. winter messenger 2
[sg function] 2021 Niuke winter vacation training camp 6 h. winter messenger 2
2022-07-03 22:03:00 【HeartFireY】
Portal :H- Winter messenger 2_2022 Niuke winter vacation algorithm basic training camp 6 (nowcoder.com)
Ideas
First, we review the theory of fair combination game P Point and N spot :
- All endpoints are fail points (P-Position)
- From any winning point (N-Position) operation , There is at least one way to enter the fail point (P-Position)
- Whatever you do , You can only enter the winning point from the losing point (N-Position)
Then let's start to analyze this topic :
- Adopt binary enumeration , use 0 0 0 representative b b b, 1 1 1 representative w w w, In this way, all combinations within a certain length can be enumerated .
- For each state , Whether enumeration can enter the mandatory state ( The initial failure state is 0 0 0), If it can, it will be marked as winning .
- For both operations :
- The first grid is white , When you can directly reverse the first lattice : If you flip the first lattice, it will fail , Then mark the current status as winning
- For the rest of the grid , If it can enter any previous failure state after completing the first type of flip , Then mark the current status as a must fail
Then according to the nature of the above two operations , We can write S G SG SG Table function :
int sg[N];
inline void getsg(){
for(int i = 1; i < (1 << 11); i++){
if(i & 1 && !sg[i - 1]){
sg[i] = 1;
continue;
}
for(int j = 1; j < 10; j++){
if(i >> j & 1){
for(int k = 0; k < j; k++)
if(!sg[i ^ (1 << j) ^ (1 << k)]) sg[i] = 1;
}
}
}
}
Then for each input , It only needs to be processed into the form of binary string , Judge S G SG SG The value of the can .
Accepted Code
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 11 + 10;
int sg[N];
string s;
void print_bin(int n){
int a = n % 2;
n = n >> 1;
if(n) print_bin(n);
std::cout << a;
}
inline void getsg(){
for(int i = 1; i < (1 << 11); i++){
if(i & 1 && !sg[i - 1]){
sg[i] = 1;
continue;
}
for(int j = 1; j < 10; j++){
if(i >> j & 1){
for(int k = 0; k < j; k++)
if(!sg[i ^ (1 << j) ^ (1 << k)]) sg[i] = 1;
}
}
}
}
inline void solve(){
getsg();
int n = 0; cin >> n >> s;
int lastpos = 0;
for(int i = 0; i < n; i++){
if(s[i] == 'w') lastpos = i;
}
int pos = 0;
for(int i = lastpos; i >= 0; i--){
if(s[i] == 'w') pos = pos << 1 | 1;
else pos = pos << 1;
}
//print_bin(pos);
cout << (sg[pos] ? "Yes" : "No") << endl;
}
signed main(){
int t = 0; cin >> t;
while(t--) solve();
return 0;
}
边栏推荐
- 抓包整理外篇——————autoResponder、composer 、statistics [ 三]
- Teach you how to install aidlux (1 installation)
- IPhone development swift foundation 09 assets
- [dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)
- What is the difference between res.send() and res.end() in the node express framework
- Report on the current situation and development trend of ethoxylated sodium alkyl sulfate industry in the world and China Ⓞ 2022 ~ 2027
- Pengcheng cup Web_ WP
- Oil monkey plug-in
- DR-AP40X9-A-Qualcomm-IPQ-4019-IPQ-4029-5G-4G-LTE-aluminum-body-dual-band-wifi-router-2.4GHZ-5GHz-QSD
- 油猴插件
猜你喜欢

Morning flowers and evening flowers

Compréhension de la technologie gslb (Global Server load balance)

TiDB 之 TiCDC6.0 初体验

What should the future of the Internet be like when Silicon Valley employees flee the big factory and rush to Web3| Footprint Analytics

Yyds dry inventory hcie security Day12: concept of supplementary package filtering and security policy

Teach you how to install aidlux (1 installation)
![[dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)](/img/6c/2d48d441fee1981a271319fd9f6c23.jpg)
[dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)

QFileDialog

Common SQL sets
![Intimacy communication -- [repair relationship] - use communication to heal injuries](/img/c2/f10405e3caf570dc6bd124d65b2e93.jpg)
Intimacy communication -- [repair relationship] - use communication to heal injuries
随机推荐
Luogu deep foundation part 1 Introduction to language Chapter 6 string and file operation
Electronic tube: Literature Research on basic characteristics of 6j1
2022 safety officer-b certificate examination summary and safety officer-b certificate simulation test questions
Data consistency between redis and database
抓包整理外篇——————autoResponder、composer 、statistics [ 三]
An expression that regularly matches one of two strings
Conditional statements of shell programming
Global and Chinese market of telematics boxes 2022-2028: Research Report on technology, participants, trends, market size and share
What is the difference between res.send() and res.end() in the node express framework
Teach you how to install aidlux (1 installation)
股票炒股开户注册安全靠谱吗?有没有风险的?
English topic assignment (28)
DR-AP40X9-A-Qualcomm-IPQ-4019-IPQ-4029-5G-4G-LTE-aluminum-body-dual-band-wifi-router-2.4GHZ-5GHz-QSD
The White House held an open source security summit, attended by many technology giants
Global and Chinese market of recycled yarn 2022-2028: Research Report on technology, participants, trends, market size and share
2022-2-14 acwing1027 grid access
Collections SQL communes
Notes on MySQL related knowledge points (startup, index)
IPhone development swift foundation 09 assets
Farmersworld farmers world, no faith, how to talk about success?