https://codeforces.com/contest/1998/problem/D
思路:求出到达每个点的最短路径,然后从每个点i考虑跳跃到点j(i->j有边),i+1默认为必胜态,则必败态为j - 从1~j的步数。
如果必败态所在的位置>必胜态,则更新差分数组,最后求和即可。
总结:一开始只考虑了从1~j的步数只能是1步1步走的,没考虑到可以跳跃移动的情况。
void solve(){
int n, m;
cin >> n >> m;
vector<vector<int>> al(n + 1);
for (int i = 1; i < n; ++i) {
al[i].push_back(i + 1);
}
for (int i = 1; i <= m; ++i) {
int u, v;
cin >> u >> v;
al[u].push_back(v);
}
queue<int> q;
q.push(1);
vector<int> dist(n + 1, 0x3f3f3f3f);
dist[1] = 0;
while (!q.empty()) {
int u = q.front();
q.pop();
for (const auto& v : al[u]) {
if (checkMin(dist[v], dist[u] + 1))
q.push(v);
}
}
vector<int> ans(n + 1);
for (int i = 1; i <= n; ++i) {
for (const auto& v : al[i]) {
int l = i + 1;
int r = v - dist[i] - 1;
if (l < r) {
ans[l] ++;
ans[r] --;
}
}
}
for (int i = 1; i < n; ++i) {
ans[i] += ans[i - 1];
cout << (ans[i] == 0);
}
cout << '\n';
}
标签:vector,dist,int,al,Winning,Race,Determine,push,Islands
From: https://www.cnblogs.com/yxcblogs/p/18375447