Codeforces 924 A Tritonic Iridescence(暴力集合交集、相等)
题目链接:点击打开链接
There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i < j) exists such that or , where denotes intersection of sets, and denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid.
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.
Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..
Yes
5 5
..#..
..#..
#####
..#..
..#..
No
5 9
........#
#........
..##.#...
.......#.
....#.#.#
No
For the first example, the desired setup can be produced by 3 operations, as is shown below.
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column.
官方题解:
No row or column can be selected more than once, hence whenever a row r is selected in an operation, all cells in it uniquely determine the set of columns that need to be selected — let's call it Sr.
Let's assume a valid set of operations exists. Take out any two rows, i and j. If rows i and j are selected in the same operation, we can deduce that Si = Sj; if they're in different operations, we get . Therefore, if Si ≠ Sj and hold for any pair of rows (i, j), no valid operation sequence can be found.
Otherwise (no pair violates the condition above), a valid sequence of operations can be constructed: group all rows with the same S's and carry out an operation with each group.
Thus, it's a necessary and sufficient condition for the answer to be "Yes", that for each pair of rows (i, j), either Si = Sj or holds.
The overall complexity is O(n2m). It can be divided by the system's word size if you're a bitset enthusiast, and a lot more if hashes and hash tables release their full power.
感想:我为啥不敢写暴力呢,
代码:吸一下getchar()和bool类型的二维数组
#include <cstdio>
typedef long long int64;
static const int MAXN = 53;
static int n, m;
static bool a[MAXN][MAXN];
static int64 b[MAXN];
int main()
{
scanf("%d%d", &n, &m); getchar();
for (int i = 0; i < n; ++i)
for (int j = 0; j <= m; ++j) a[i][j] = (getchar() == '#');
for (int i = 0; i < n - 1; ++i)
for (int j = i + 1; j < n; ++j) {
bool all_same = true, no_intersect = true;
for (int k = 0; k < m; ++k) {
if (a[i][k] != a[j][k]) all_same = false;
if (a[i][k] && a[j][k]) no_intersect = false;
}
if (!all_same && !no_intersect) {
puts("No"); return 0;
}
}
puts("Yes"); return 0;
}
Codeforces 924 A Tritonic Iridescence(暴力集合交集、相等)的更多相关文章
- codeforces 957 A. Tritonic Iridescence
题意: 给出一个字符串,要求任意两个相同的字母不能相同,问这个字符串是否能有两种或者两种以上的表现形式. 思路: 简单判断一下: 1.问号在端点: 2.连续两个问号或者以上: 3.一个问号两端的字母是 ...
- C# List 集合 交集、并集、差集、去重, 对象集合、 对象、引用类型、交并差补、List<T>
关键词:C# List 集合 交集.并集.差集.去重, 对象集合. 对象.引用类型.交并差.List<T> 有时候看官网文档是最高效的学习方式! 一.简单集合 Intersect 交集, ...
- 关于C++里set_intersection(取集合交集)、set_union(取集合并集)、set_difference(取集合差集)等函数的使用总结
文章转载自https://blog.csdn.net/zangker/article/details/22984803 set里面有set_intersection(取集合交集).set_union( ...
- Codeforces 839D Winter is here - 暴力 - 容斥原理
Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n s ...
- spark 集合交集差集运算
intersect except是spark提供的集合差集运算, 但是要求参与运算的两个dataframe,有相同的data Schema. 如果我想从 集合1(attribute1, attribu ...
- Codeforces Gym 100015H Hidden Code 暴力
Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...
- Codeforces gym 100685 A. Ariel 暴力
A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...
- Codeforces Gym 100637G G. #TheDress 暴力
G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...
- CodeForces 277A Learning Languages (并检查集合)
A. Learning Languages time limit per test:2 seconds memory limit per test:256 megabytes The "Be ...
随机推荐
- MyBatis项目实战 快速将MySQL转换成Oracle语句
一.前言 因项目需求,小编要将项目从mysql迁移到oracle中 ~ 之前已经完成 数据迁移 (https://zhengqing.blog.csdn.net/article/details/103 ...
- 投票:OAuth2.0 技术选型你会怎么选
1. 前言 在使用 OAuth2.0 中 Authorization Server (授权服务器)是一个回避不了的设施,在大多数情况下我们调用的是一些知名的.可靠的.可信任的第三方平台,比如 QQ.微 ...
- AcWing 251. 小Z的袜子| 分块+莫队
传送门 题目描述 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿. 终于有一天,小Z再也无法忍受这恼人的找袜子过程,于是他决定听天由命. 具体来说,小Z把这N只袜子从 ...
- 查找2-n之间素数的个数
题目描述 查找2-n之间素数的个数.n为用户输入值.素数:一个大于1的正整数,如果除了1和它本身以外,不能被其他正整数整除,就叫素数.如2,3,5,7,11,13,17…. 输入 整数n 输出 2-n ...
- [AI开发]小型数据集解决实际工程问题——交通拥堵、交通事故实时告警
这篇文章其实主要是想介绍在深度学习过程中如何使用小型数据集,这种数据集样本数量一般在1000以下,有时候甚至只有几百.一般提到神经网络,大家都会说数据量越丰富,准确性越高,但是实际工作中,可能收集不了 ...
- Java小白集合源码的学习系列:LinkedList
目录 LinkedList 源码学习 LinkedList继承体系 LinkedList核心源码 Deque相关操作 总结 LinkedList 源码学习 前文传送门:Java小白集合源码的学习系列: ...
- 云原生 - 体验Istio的完美入门之旅(一)
作者:justmine 头条号:大数据达摩院 微信公众号:大数据处理系统 创作不易,在满足创作共用版权协议的基础上可以转载,但请以超链接形式注明出处. 为了方便大家阅读,可以关注头条号或微信公众号,后 ...
- 关于爬虫的日常复习(17)——scrapy系列1
- Excel-条件格式
今天运用了一下条件格式中的自建规则进行公式筛选, 设置格式那里一定要将$P$8修改为$P8 然后双击修改后的第一项进行单元格的自动填充
- pyton 封装
定义:在类中将方法和属性隐藏起来 一.私有化 1.格式 __名字,在名字前加双下划线 2.私有化对象 对象属性 静态属性 普通方法 3.作用 1)在类的外面不能直接调用类的方法和属性 2)类的属性值不 ...