Codeforces Round #363 (Div. 2) B. One Bomb —— 技巧
题目链接:http://codeforces.com/contest/699/problem/B
题解:
首先统计每行每列出现‘*’的次数,以及‘*’出现的总次数,得到r[n]和c[m]数组,以及sum,。然后再枚举每一个格子(O(n^2)枚举,反正输入都是枚举的)。
对于每一个格子s[i][j]:
1.如果它是‘*’, 那么当 r[i] + c[j] - 1 = sum 时, 表明炸弹放在这个位置可以炸掉所有的墙。
2.如果它是‘.’, 那么当 r[i] + c[j] = sum 时, 表明炸弹放在这个位置可以炸掉所有的墙。
这个规律还是要画图才比较好找出来的……
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#include <algorithm>
using namespace std;
#define pb push_back
#define mp make_pair
#define ms(a, b) memset((a), (b), sizeof(a))
#define eps 0.0000001
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+7;
const int maxn = 200000+10; int n,m;
char s[1005][1005];
int r[1005], c[1005]; void init()
{
scanf("%d%d",&n,&m);
for(int i = 1; i<=n; i++)
scanf("%s",s[i]+1); ms(c,0);
ms(r,0);
} void solve()
{
int sum = 0;
for(int i = 1; i<=n; i++)
for(int j = 1; j<=m; j++)
if(s[i][j] == '*')
sum++, r[i]++, c[j]++; int B = 0, x, y;
for(int i = 1; i<=n; i++)
for(int j = 1; j<=m; j++)
{
int tmp = r[i]+c[j];
if(s[i][j]=='*')
tmp--; if(tmp==sum)
{
B = 1;
x = i; y = j;
break;
}
} if(B)
printf("YES\n%d %d\n",x,y);
else
puts("NO");
} int main()
{
// int T;
// scanf("%d",&T);
// while(T--)
{
init();
solve();
}
return 0;
}
Codeforces Round #363 (Div. 2) B. One Bomb —— 技巧的更多相关文章
- Codeforces Round #363 (Div. 2)->B. One Bomb
B. One Bomb time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Codeforces Round #363 (Div. 2) B. One Bomb (水题)
B. One Bomb time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Codeforces Round 363 Div. 1 (A,B,C,D,E,F)
Codeforces Round 363 Div. 1 题目链接:## 点击打开链接 A. Vacations (1s, 256MB) 题目大意:给定连续 \(n\) 天,每天为如下四种状态之一: 不 ...
- Codeforces Round #363 (Div. 2) One Bomb
One Bomb 题意: 只有一个炸弹,并且一个只能炸一行和一列的'*',问最后能否炸完所以'*',如果可以输出炸弹坐标 题解: 这题做的时候真的没什么好想法,明知道b题应该不难,但只会瞎写,最后越写 ...
- Codeforces Round #345 (Div. 1) E. Clockwork Bomb 并查集
E. Clockwork Bomb 题目连接: http://www.codeforces.com/contest/650/problem/E Description My name is James ...
- Codeforces Round #363 (Div. 2)
A题 http://codeforces.com/problemset/problem/699/A 非常的水,两个相向而行,且间距最小的点,搜一遍就是答案了. #include <cstdio& ...
- Codeforces Round #363 Div.2[111110]
好久没做手生了,不然前四道都是能A的,当然,正常发挥也是菜. A:Launch of Collider 题意:20万个点排在一条直线上,其坐标均为偶数.从某一时刻开始向左或向右运动,速度为每秒1个单位 ...
- Codeforces Round #363 (Div. 1) B. Fix a Tree 树的拆环
题目链接:http://codeforces.com/problemset/problem/698/B题意:告诉你n个节点当前的父节点,修改最少的点的父节点使之变成一棵有根树.思路:拆环.题解:htt ...
- Codeforces Round #363 (Div. 2) A、B、C
A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
随机推荐
- mc
Description 小C在MC里有n个牧场,自西向东呈一字形排列(自西向东用1-n编号),于是他就烦恼了:为了控制这n个牧场,他需要在某些牧场上面建立控制站, 每个牧场上只能建立一个控制站,每个控 ...
- Ubuntu 16.04下使用Wine安装Windows版的微信(不太完美)
说明: 真的不太完美,别试了:除了需要安装额外的输入法之后,无法上传图片和间接性的BUG出现等等问题. 建议安装网页版的微信:http://www.cnblogs.com/EasonJim/p/711 ...
- oceanbase 分布式数据库
http://blog.csdn.net/maray/article/details/7230881 http://weibo.com/raywill2
- awk的求和计算使用;awk多个分隔符如何使用?
1.对于下图,如何使用awk求所有各列的和 和:175 16 78 19 方法:awk '{for(n=1;n<=NF;n++)t[n]+=$n}END{for(n=1;n<=NF;n++ ...
- jenkins执行单元测试,会产生大量临时文件,要及时删除,不然会把inode耗尽
jenkins的build命令:clean test -U findbugs:findbugs pmd:pmd sonar:sonar -Djava.io.tmpdir=/tmp/ -Dsonar.p ...
- 【Todo】Tomcat与Jetty的比较 以及Tomcat架构的学习
主要参考这篇文章: http://blog.csdn.net/qing_2012/article/details/8276789 然后Tomcat原理的介绍,可以看这篇文章: http://www.i ...
- [反汇编练习] 160个CrackMe之033
[反汇编练习] 160个CrackMe之033. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...
- C# Ftp方式下载文件(无用户认证方式,支持断点续传)
类代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sys ...
- WinDbg加载不同版本CLR
WinDbg调试.net2.0和.net4.0程序有所不同,因为.net4.0使用新版本的CLR.例如: mscoree.dll 变为 mscoree.dll 和 mscoreei.dll, msco ...
- 斯坦福公开课:Developing IOS 8 App with Swift(1-3)心得体会
最近开始学习Swift开发移动程序.跟随斯坦福大学的公开课进行自学. 这真是一个美好的时代,虽然不能在斯坦福求学,但是可以观看录制的授课录像.讲义,好似老师在给我们上课一样! 心得: 1.每节课信息量 ...