CF-Educational Codeforces Round 44 (Rated for Div. 2)-B-Switches and Lamps
程序员文章站
2022-06-03 19:31:39
...
描述
题解
每个开关都能控制一些灯,但是只能打开灯,同一盏灯被多个开关操作,操作一次的结果是灯亮,操作数次结果还是灯亮。问能否取 个开关让所有灯亮。很简单的题,记录开每个灯的开关数,然后逐个剔除开关,判断是否全开。注意可能存在所有开关都选的时候依然无法全开的情况。
代码
#include <iostream>
#include <cstring>
using namespace std;
const int MAXN = 2222;
int n, m;
char vis[MAXN][MAXN];
int cnt[MAXN];
int main(int argc, const char * argv[])
{
while (cin >> n >> m)
{
memset(cnt, 0, sizeof(cnt));
for (int i = 1; i <= n; i++)
{
scanf("%s", vis[i] + 1);
for (int j = 1; j <= m; j++)
{
if (vis[i][j] == '1')
{
cnt[j]++;
}
}
}
int flag = 0;
for (int i = 1; i <= m; i++)
{
if (cnt[i] == 0)
{
flag = 1;
break;
}
}
if (flag)
{
cout << "NO\n";
continue;
}
for (int i = 1; i <= n; i++)
{
int tag = 1;
for (int j = 1; j <= m; j++)
{
if (vis[i][j] == '1' && cnt[j] - 1 == 0)
{
tag = 0;
break;
}
}
if (tag)
{
cout << "YES\n";
flag = 1;
break;
}
}
if (!flag)
{
cout << "NO\n";
}
}
return 0;
}
推荐阅读
-
Educational Codeforces Round 71 (Rated for Div. 2)E. XOR Guessing
-
Educational Codeforces Round 97 (Rated for Div. 2) D. Minimal Height Tree
-
Educational Codeforces Round 60 (Rated for Div. 2) ----A - Best Subsegment(思维题)
-
Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) E. DNA Evolution(多颗树状数组+思维)
-
【解题报告】Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)
-
Educational Codeforces Round 85 (Rated for Div. 2) C. Circle of Monsters(前缀和 预处理 贪心)
-
Educational Codeforces Round 98 (Rated for Div. 2) A-E 题解
-
Educational Codeforces Round 93 (Rated for Div. 2) A. Bad Triangle
-
Educational Codeforces Round 93 (Rated for Div. 2) B - Substring Removal Game
-
Educational Codeforces Round 99 (Rated for Div. 2) C. Ping-pong