VK Cup 2018 Round 2: A. Mystical Mosaic(思维)
2018-03-25 16:28
387 查看
B. Mystical Mosaictime limit per test 1 secondmemory limit per test 256 megabytesinput standard inputoutput standard outputThere 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.InputThe 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.OutputIf 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).Examplesinput
题意:一个n*m的矩阵,一开始所有格子都是空的,你每次可以选择若干列和若干行,并在这些行和列的交点上放上一枚棋子,每一行/列至多被选一次,先给你一种最终情况,问你能否实现
仔细分析一下就会发现,如果有三个棋子在某个矩形的三个顶点上,那么这个矩形的第四个顶点上一定要有棋子(三个棋子作为定点可以构成一个直角三角形,其中直角边平行于x轴和y轴,那么这三个棋子就一定在某个矩形的三个顶点上)
所以只要暴力枚举任意一对棋子作为矩形的其中一条斜对角线,然后判断下另一条对角线上棋子情况就OK了
复杂度O(n²m²)
#include<stdio.h>
char str[55][55];
int main(void)
{
int n, m, i, j, x, y;
scanf("%d%d", &n, &m);
for(i=1;i<=n;i++)
scanf("%s", str[i]+1);
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(str[i][j]=='.')
continue;
for(x=1;x<=n;x++)
{
for(y=1;y<=n;y++)
{
if(str[x][y]=='.' || i==x || j==y)
continue;
if(str[i][y]=='#' && str[x][j]=='.' || str[i][y]=='.' && str[x][j]=='#')
{
printf("No\n");
return 0;
}
}
}
}
}
printf("Yes\n");
return 0;
}
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.InputThe 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.OutputIf 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).Examplesinput
5 8 .#.#..#. .....#.. .#.#..#. #.#....# .....#..output
Yesinput
5 5 ..#.. ..#.. ##### ..#.. ..#..output
Noinput
5 9 ........# #........ ..##.#... .......#. ....#.#.#output
No
题意:一个n*m的矩阵,一开始所有格子都是空的,你每次可以选择若干列和若干行,并在这些行和列的交点上放上一枚棋子,每一行/列至多被选一次,先给你一种最终情况,问你能否实现
仔细分析一下就会发现,如果有三个棋子在某个矩形的三个顶点上,那么这个矩形的第四个顶点上一定要有棋子(三个棋子作为定点可以构成一个直角三角形,其中直角边平行于x轴和y轴,那么这三个棋子就一定在某个矩形的三个顶点上)
所以只要暴力枚举任意一对棋子作为矩形的其中一条斜对角线,然后判断下另一条对角线上棋子情况就OK了
复杂度O(n²m²)
#include<stdio.h>
char str[55][55];
int main(void)
{
int n, m, i, j, x, y;
scanf("%d%d", &n, &m);
for(i=1;i<=n;i++)
scanf("%s", str[i]+1);
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(str[i][j]=='.')
continue;
for(x=1;x<=n;x++)
{
for(y=1;y<=n;y++)
{
if(str[x][y]=='.' || i==x || j==y)
continue;
if(str[i][y]=='#' && str[x][j]=='.' || str[i][y]=='.' && str[x][j]=='#')
{
printf("No\n");
return 0;
}
}
}
}
}
printf("Yes\n");
return 0;
}
相关文章推荐
- VK Cup 2018 Round 2: C. Riverside Curio(思维)
- VK Cup 2018 Round 2 div2 C, D 题解 【思维题】
- VK Cup 2018 Round 2: D. Contact ATC(思维+树状数组)
- VK Cup 2018 Round 1: A. Primal Sport
- VK Cup 2018 - Round 2 C. Riverside Curio
- Codeforces Round #470 (VK Cup 2018 Round 1)
- VK Cup 2018 Round 2: B. Three-level Laser 二分+贪心
- VK Cup 2018 Round 1 and CF Round #470 div2 C
- VK Cup 2018 - Round 1 A. Primal Sport
- codeforce Mystical Mosaic(VK Cup 2018 - Round 2)
- VK Cup 2018 Round 2: B. Three-level Laser(二分)
- VK Cup 2018 Round 1: D. Picking Strings
- VK Cup 2018 - Round 2 C - Riverside Curio 贪心
- VK Cup 2018 Round 1: C. Perfect Security(01字典树)
- VK Cup 2018 Round 1: B. Producing Snow
- Codeforces Round #253 (Div. 2) E. Artem and Array (思维)
- Codeforces Round #426 (Div. 2) C. The Meaningless Game 思维 D. The Bakery dp
- Educational Codeforces Round 26 C - Two Seals【略带贪心+思维】好题
- Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)C. Producing Snow
- Codeforces Round #387(Div. 2)D. Winter Is Coming【思维+dp】