当前位置:网站首页>Winter messenger 2
Winter messenger 2
2022-07-05 06:19:00 【Strezia】
Link
Game theory ,sg function
I didn't understand the solution ,, Violence made a watch , At the beginning, I also operated 2 It's missing .
Looking at the solution means that every operation will make x x x Reduce , After doing several questions, I feel that if there are multiple operations , Then find the common ground of these operations , To write the transfer equation .
Code
int sg[1050];
int mex(vector<int> v) // v It can be vector、set Equal container
{
unordered_set<int> S;
for (auto e : v)
S.insert(e);
for (int i = 0;; ++i)
if (S.find(i) == S.end())
return i;
}
int cal(int x) {
if(sg[x] != -1) return sg[x];
int t = x;
vector<int> v;
if(t & 1) {
v.pb(cal(t - 1));
}
for(int i = 0; i < 10; i++) {
if(!(t >> i)) break;
if((t >> i) & 1) {
int p = x ^ (1<<i);
for(int j = i - 1; j >= 0; j--) {
int q = p ^ (1<<j);
v.pb(cal(q));
}
}
}
int a = mex(v);
return sg[x] = a;
}
void solve() {
int n;
cin >> n;
string s;
cin >> s;
int a = 0;
for(int i = 0; i < n; i++) {
if(s[i] == 'w')
a = a + (1<<i);
}
if(sg[a]) cout << "Yes\n";
else cout << "No\n";
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
memset(sg, -1, sizeof(sg));
sg[0] = 0;
for(int i = 1; i <= 1030; i++)
cal(i);
int T; cin >> T; while(T--)
solve();
return 0;
}
边栏推荐
- Leetcode-6109: number of people who know secrets
- Winter vacation water test 1 Summary
- [rust notes] 14 set (Part 1)
- New title of module a of "PanYun Cup" secondary vocational network security skills competition
- Applicable to Net free barcode API [off] - free barcode API for NET [closed]
- liunx启动redis
- Leetcode dynamic programming
- Traversal of leetcode tree
- 一些工具的记录2022
- 【Rust 笔记】16-输入与输出(上)
猜你喜欢
[2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian
传统数据库逐渐“难适应”,云原生数据库脱颖而出
Operator priority, one catch, no doubt
Gaussian elimination acwing 884 Gauss elimination for solving XOR linear equations
中国剩余定理 AcWing 204. 表达整数的奇怪方式
Appium基础 — 使用Appium的第一个Demo
阿里巴巴成立企业数智服务公司“瓴羊”,聚焦企业数字化增长
什么是套接字?Socket基本介绍
MySQL advanced part 2: SQL optimization
Sqlmap tutorial (II) practical skills I
随机推荐
Appium基础 — 使用Appium的第一个Demo
MySQL advanced part 1: index
【Rust 笔记】17-并发(上)
Leetcode divide and conquer / dichotomy
[rust notes] 17 concurrent (Part 1)
NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
Is it impossible for lamda to wake up?
Nested method, calculation attribute is not applicable, use methods
redis发布订阅命令行实现
Filter the numbers and pick out even numbers from several numbers
【Rust 笔记】17-并发(下)
LeetCode-61
Quickly use Amazon memorydb and build your own redis memory database
QQ computer version cancels escape character input expression
1039 Course List for Student
[leetcode] day95 effective Sudoku & matrix zeroing
In depth analysis of for (VaR I = 0; I < 5; i++) {settimeout (() => console.log (I), 1000)}
可变电阻器概述——结构、工作和不同应用
Appium自动化测试基础 — Appium测试环境搭建总结
[rust notes] 13 iterator (Part 2)