【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",&n,&m); for(int i=1;i<=n;i++){ scanf("%s",&ma[i]); for(int j=1;j<=m;j++){ if(ma[i][j-1]=='*'){ num++; r[i]++; c[j]++; } } } int ok=0; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { int s=r[i]+c[j]; if(ma[i][j-1]=='*')s--; if(s==num){ ok=1; x=i; y=j; } } if(ok) { puts("YES"); printf("%d %d",x,y); } else printf("NO"); }
┆凉┆暖┆降┆等┆幸┆我┆我┆里┆将┆ ┆可┆有┆谦┆戮┆那┆ ┆大┆始┆ ┆然┆
┆薄┆一┆临┆你┆的┆还┆没┆ ┆来┆ ┆是┆来┆逊┆没┆些┆ ┆雁┆终┆ ┆而┆
┆ ┆暖┆ ┆如┆地┆站┆有┆ ┆也┆ ┆我┆ ┆的┆有┆精┆ ┆也┆没┆ ┆你┆
┆ ┆这┆ ┆试┆方┆在┆逃┆ ┆会┆ ┆在┆ ┆清┆来┆准┆ ┆没┆有┆ ┆没┆
┆ ┆生┆ ┆探┆ ┆最┆避┆ ┆在┆ ┆这┆ ┆晨┆ ┆的┆ ┆有┆来┆ ┆有┆
┆ ┆之┆ ┆般┆ ┆不┆ ┆ ┆这┆ ┆里┆ ┆没┆ ┆杀┆ ┆来┆ ┆ ┆来┆