前缀和思维C. Omkar and Determination
Posted 行码棋
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了前缀和思维C. Omkar and Determination相关的知识,希望对你有一定的参考价值。
https://codeforces.com/problemset/problem/1583/C
一个网格,可以向上或向左走。为
X
表示堵塞不能走,为.
表示可以走
如果一个.
处的位置可以在左边或上边走出方格,那么结果就是E
可走出的,否则为N
给出一个方格图,然后可以得到方格图的每个方格是否可以走出的图,问是否能够通过该图得到原方格图
这道题真的很妙
考虑一定不会满足的情况,下面的情况右下角一定不满足,因为他可以是.
也可以是X
,这种情况不能确定
?X
X?
我们用cnt[i]
统计第i-1
列情况下 第i
列的不能确定方格的个数
然后对cnt
做一下前缀和,对于每一次l,r
询问
如果
c
n
t
[
r
]
=
=
c
n
t
[
l
]
cnt[r] == cnt[l]
cnt[r]==cnt[l]说明在
[
l
,
r
]
[l,r]
[l,r]之间没有新增的不能猜测的点,所以可以得到原图
否则就不可以得到原图
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1e5 + 5;
void solve()
int n, m;
cin >> n >> m;
vector<string> s(n + 1);
for(int i = 1; i <= n; i++)
cin >> s[i];
vector<int> cnt(m + 1, 0);
for(int i = 2; i <= n; i++)
for(int j = 2; j <= m; j++)
if(s[i][j - 2] == 'X' && s[i - 1][j - 1] == 'X')
cnt[j] ++;
for(int i = 1; i <= m; i++)
cnt[i] += cnt[i - 1];
int q;
cin >> q;
while(q--)
int l, r;
cin >> l >> r;
if(cnt[r] == cnt[l]) cout << "YES\\n";
else cout << "NO\\n";
int main()
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
// cin >> t;
t = 1;
while(t--) solve();
return 0;
以上是关于前缀和思维C. Omkar and Determination的主要内容,如果未能解决你的问题,请参考以下文章
[Codeforces 1586] Omkar and Determination | 思维前缀和
C. Pluses and Minuses 1300 / 思维 前缀和
D - Omkar and Medians(数据结构+思维)
Codeforces Round #724 (Div. 2)1536E - Omkar and Forest(思维,结论)
[每日一题]:Codeforces Round #632 (Div. 2) C. Eugene and an array