【模拟】Codeforces 699B One Bomb

题目链接:

  http://codeforces.com/problemset/problem/699/B

题目大意:

  N*M的图,*代表墙.代表空地。问能否在任意位置(可以是墙上)放一枚炸弹(能炸所在行和列),把所有的墙都炸掉。输出答案(不唯一)。

题目思路:

  【模拟】

  N2预处理出每一行能炸多少墙,每一列能炸多少墙。再N2枚举放炸弹的位置看能炸掉的墙数目是否等于总数。注意如果炸弹位置上有墙要-1。

 1 //
 2 //by coolxxx
 3 ////<bits/stdc++.h>
 4 #include<iostream>
 5 #include<algorithm>
 6 #include<string>
 7 #include<iomanip>
 8 #include<map>
 9 #include<memory.h>
10 #include<time.h>
11 #include<stdio.h>
12 #include<stdlib.h>
13 #include<string.h>
14 //#include<stdbool.h>
15 #include<math.h>
16 #define min(a,b) ((a)<(b)?(a):(b))
17 #define max(a,b) ((a)>(b)?(a):(b))
18 #define abs(a) ((a)>0?(a):(-(a)))
19 #define lowbit(a) (a&(-a))
20 #define sqr(a) ((a)*(a))
21 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
22 #define mem(a,b) memset(a,b,sizeof(a))
23 #define eps (1e-8)
24 #define J 10
25 #define MAX 0x7f7f7f7f
26 #define PI 3.14159265358979323
27 #define N 1004
28 using namespace std;
29 typedef long long LL;
30 int cas,cass;
31 int n,m,lll,ans;
32 char ss[N][N];
33 int a[N],b[N];
34 void work(int *i,int *j)
35 {
36     for((*i)=1;(*i)<=n;(*i)++)
37     {
38         for((*j)=1;(*j)<=m;(*j)++)
39         {
40             if(a[(*i)]+b[(*j)]-(ss[(*i)][(*j)]==‘*‘)==lll)return;
41         }
42     }
43 }
44 int main()
45 {
46     #ifndef ONLINE_JUDGE
47     freopen("1.txt","r",stdin);
48 //    freopen("2.txt","w",stdout);
49     #endif
50     int i,j;
51 //    for(scanf("%d",&cas);cas;cas--)
52 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
53     while(~scanf("%d",&n))
54 //    while(~scanf("%d",&n))
55     {
56         scanf("%d",&m);
57         mem(a,0);mem(b,0);lll=0;
58         for(i=1;i<=n;i++)
59         {
60             scanf("%s",ss[i]+1);
61         }
62         for(i=1;i<=n;i++)
63         {
64             for(j=1;j<=m;j++)
65             {
66                 if(ss[i][j]==‘*‘)a[i]++,b[j]++,lll++;
67             }
68         }
69         work(&i,&j);
70         if(i>n)puts("NO");
71         else printf("YES\n%d %d\n",i,j);
72     }
73     return 0;
74 }
75 /*
76 //
77
78 //
79 */

时间: 2025-01-05 02:32:21

【模拟】Codeforces 699B One Bomb的相关文章

【打CF,学算法——二星级】Codeforces 699B - One Bomb (技巧)

[CF简介] 题目链接:CF 699B 题面: B. One Bomb time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a description of a depot. It is a rectangular checkered field of n?×?m size. Each cell in a

CodeForces 699B One Bomb

把每一个墙的位置都存下来. 如果墙的个数$sz>n+m$,显然无解. 否则枚举炸哪一行,假设枚举炸第$i$行,去掉第$i$行的所有墙,看剩下的墙是否处于同一列,如果是,那么这就是一个解. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm&g

【CodeForces 699B】One Bomb

r[i],c[i]分别表示第i行有几个*,第i列有几个*. 枚举每个位置如果c[i]+r[j]-(本身是不是*)==总*数,则该位置即为答案. #include<cstdio> #include<cstring> #include<algorithm> #define N 10050 using namespace std; int n,m,r[N],c[N],x,y,num; char ma[N][N]; int main(){ scanf("%d%d&qu

模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie

题目传送门 1 /* 2 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 3 题目倒是很长:) 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <iostream> 8 #include <algorithm> 9 #include <cstring> 10 using namespace std; 11 12 const int MAXN = 2e5 + 10; 13

queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards

题目传送门 1 /* 2 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 3 queue容器:模拟上述过程,当次数达到最大值时判断为-1 4 */ 5 #include <cstdio> 6 #include <iostream> 7 #include <algorithm> 8 #include <cstring> 9 #include <string> 10 #include <stack> 11 #in

codeforces 591B Rebranding (模拟)

Rebranding Problem Description The name of one small but proud corporation consists of n lowercase English letters. The Corporation has decided to try rebranding - an active marketing strategy, that includes a set of measures to change either the bra

Codeforces 747C:Servers(模拟)

http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开始,如果可以完成任务,那么输出id总和,否则输出-1. 思路:简单的模拟,注意如果不能完成任务,那么ser数组是不能更新的. 1 #include <cstdio> 2 #include <algorithm> 3 #include <iostream> 4 #includ

【模拟】Codeforces 706A Beru-taxi

题目链接: http://codeforces.com/problemset/problem/706/A 题目大意: 家的坐标在sx,sy,有n辆车,每辆车坐标xi,yi,速度vi,问最快的一辆车什么时候到家. 题目思路: [模拟] 签到题. 1 // 2 //by coolxxx 3 // 4 #include<iostream> 5 #include<algorithm> 6 #include<string> 7 #include<iomanip> 8

树状数组模拟3个元素的排序 Codeforces 12D Ball

http://codeforces.com/problemset/problem/12/d Ball time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output N ladies attend the ball in the King's palace. Every lady can be described with three val