B. One Bomb
来源:互联网 发布:thinkphp nginx 配置 编辑:程序博客网 时间:2024/04/30 05:23
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*").
You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.
You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall.
The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field.
The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall.
If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes).
Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them.
3 4.*.......*..
YES1 2
3 3..*.*.*..
NO
6 5..*....*..*****..*....*....*..
YES3 3
解题说明:此题很像以前玩过的一个猪放炸弹的游戏,问使用一颗炸弹把所有墙都炸毁的可能性。容易想到的做法是记录下所有墙的位置,然后遍历图中全部节点,判断墙的行或列是否和该点行列相同,输出找到满足要求的的第一个点即可。
#include<cstdio>#include <cstring>#include<cmath>#include<iostream>#include<algorithm>#include<vector>#include <map>using namespace std;int main(){ int n , m , k , i , j , t = 0 ;char s[1002][1002]; int row[1000] = {0} , col[1000] = {0}; scanf("%d%d",&n,&m); for(i = 0 ; i<n ; i++) { scanf("%s",s[i]); for(j=0 ; j<m ; j++) { if(s[i][j]=='*'){row[i]++;col[j]++;t++;} } } for(i = 0 ; i<n ; i++) { for(j=0 ; j<m ; j++) { if(row[i]+col[j] - (s[i][j]=='*')==t ) { printf("YES\n"); printf("%d %d",i+1,j+1); return 0 ; } } } printf("NO\n"); return 0 ;}
- 699B - One Bomb
- B - One Bomb
- B. One Bomb
- Codeforces 699B One Bomb
- codeforces 699B One Bomb
- codeforces 699B One Bomb
- Codeforces 699B - One Bomb
- Codeforces-699B One Bomb
- CodeForces 699B One Bomb
- CodeForces 699B One Bomb
- CodeForces 699B One Bomb
- Codeforces 699B - One Bomb
- B. One Bomb(水题)
- CodeForces:699B-One Bomb
- 【CF 699B】One Bomb(思维)
- Codeforces 399B. One Bomb (模拟)
- CodeForces 699B One Bomb(暴力)
- codeforces 699B One Bomb (思维)
- 为ios工程添加 .dylib库 的方法,libz.dylib libsqlite3.dylib等等
- Android 自定义view第二弹——组合控件
- android studio主题设置
- SpringBoot @EnableAutoConfiguration原理
- 后缀数组(长度不小于k的公共子串的个数)
- B. One Bomb
- sockaddr_in , sockaddr , in_addr区别Socket编程函数集(非常有用)
- 【Unity】SQLite在Unity中的使用-思维导图
- /dev/mem可没那么简单
- php协程(Coroutine)学习笔记
- Drools规则引擎(二)-Drools-Example
- Chrome上面按住Shift+鼠标左键双击会直接弹出“检查”代码的窗口
- 以太坊虚拟机实现分析
- js实现上传多个图片或者多个文件