当前位置:网站首页>[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;
}
边栏推荐
- The post-90s resigned and started a business, saying they would kill cloud database
- Why use pycharm to run the use case successfully but cannot exit?
- [dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)
- Yyds dry inventory hcie security Day12: concept of supplementary package filtering and security policy
- How does sentinel, a traffic management artifact, make it easy for business parties to access?
- 2022 electrician (elementary) examination questions and electrician (elementary) registration examination
- IPhone development swift foundation 08 encryption and security
- 2022 safety officer-a certificate registration examination and summary of safety officer-a certificate examination
- Let me ask you a question. Have you ever used the asynchronous io of Flink SQL to associate dimension tables in MySQL? I set various settings according to the official website
- 抓包整理外篇——————autoResponder、composer 、statistics [ 三]
猜你喜欢

treevalue——Master Nested Data Like Tensor

Control loop of program (while loop)

2022 safety officer-a certificate registration examination and summary of safety officer-a certificate examination

Awk getting started to proficient series - awk quick start

Asynchronous artifact: implementation principle and usage scenario of completable future

90 後,辭職創業,說要卷死雲數據庫

The latest analysis of crane driver (limited to bridge crane) in 2022 and the test questions and analysis of crane driver (limited to bridge crane)

2022 G3 boiler water treatment registration examination and G3 boiler water treatment examination papers

2022 free examination questions for safety management personnel of hazardous chemical business units and reexamination examination for safety management personnel of hazardous chemical business units

Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
随机推荐
The 14th five year plan for the construction of Chinese Enterprise Universities and the feasibility study report on investment Ⓓ 2022 ~ 2028
Asynchronous artifact: implementation principle and usage scenario of completable future
No more! Technical team members resign collectively
Covariance
鹏城杯 WEB_WP
Farmersworld farmers world, no faith, how to talk about success?
China HDI market production and marketing demand and investment forecast analysis report Ⓢ 2022 ~ 2028
Leetcode problem solving - 235 Nearest common ancestor of binary search tree
[dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)
Bluebridge cup Guoxin Changtian single chip microcomputer -- hardware environment (I)
Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
Rest reference
Dynamic research and future planning analysis report of China's urban water supply industry Ⓝ 2022 ~ 2028
Control loop of program (while loop)
2022-2-14 acwing1027 grid access
Yyds dry inventory hcie security Day12: concept of supplementary package filtering and security policy
Supply and demand situation and market scale calculation report of China's portable energy storage power PES industry Ⓛ 2022 ~ 2028
Implementation principle of inheritance, encapsulation and polymorphism
Great gods, I want to send two broadcast streams: 1. Load basic data from MySQL and 2. Load changes in basic data from Kafka
China's Call Center Industry 14th five year plan direction and operation analysis report Ⓔ 2022 ~ 2028