当前位置:网站首页>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-54
- Traversal of leetcode tree
- 1.15 - input and output system
- Appium foundation - use the first demo of appium
- LeetCode 1200. Minimum absolute difference
- Niu Mei's math problems
- How to set the drop-down arrow in the spinner- How to set dropdown arrow in spinner?
- MySQL advanced part 2: storage engine
- 4. 对象映射 - Mapping.Mapster
- Multi screen computer screenshots will cut off multiple screens, not only the current screen
猜你喜欢

MySQL advanced part 2: SQL optimization

数据可视化图表总结(一)

容斥原理 AcWing 890. 能被整除的数

Arduino 控制的 RGB LED 无限镜

Liunx starts redis

WordPress switches the page, and the domain name changes back to the IP address

1.15 - input and output system

Spark中groupByKey() 和 reduceByKey() 和combineByKey()

Sqlmap tutorial (II) practical skills I

博弈论 AcWing 894. 拆分-Nim游戏
随机推荐
中国剩余定理 AcWing 204. 表达整数的奇怪方式
MySQL advanced part 2: the use of indexes
开源存储这么香,为何我们还要坚持自研?
Is it impossible for lamda to wake up?
数据可视化图表总结(一)
Leetcode-22: bracket generation
Open source storage is so popular, why do we insist on self-development?
【Rust 笔记】17-并发(上)
Chapter 6 relational database theory
Navicat连接Oracle数据库报错ORA-28547或ORA-03135
Navicat連接Oracle數據庫報錯ORA-28547或ORA-03135
Golang uses context gracefully
1040 Longest Symmetric String
2021apmcm post game Summary - edge detection
LVS简介【暂未完成(半成品)】
【Rust 笔记】13-迭代器(下)
[rust notes] 16 input and output (Part 2)
Leetcode-556: the next larger element III
4. Object mapping Mapster
CPU内核和逻辑处理器的区别