/ CYOJ /

记录详情

Accepted


  
[Hydro](https://hydro.ac)提供评测服务
# 状态 耗时 内存占用
#1 Accepted 3ms 256.0 KiB
#2 Accepted 1ms 256.0 KiB
#3 Accepted 2ms 256.0 KiB
#4 Accepted 1ms 256.0 KiB
#5 Accepted 3ms 256.0 KiB
#6 Accepted 4ms 384.0 KiB
#7 Accepted 3ms 384.0 KiB
#8 Accepted 2ms 384.0 KiB
#9 Accepted 2ms 384.0 KiB
#10 Accepted 87ms 1.242 MiB

代码

#include<bits/stdc++.h>
using namespace std;
bool k[1005][1005];
int main() {
	int r,c;
	scanf("%d%d",&r,&c);
	char b;
	for(int i = 1;i <= r;i++) {
		for(int j = 1;j <= c;j++) {
			cin>>b;
			if(b == '#') {
				k[i][j] = 1;
				continue;
			}	
			k[i][j] = 0;
		}
	}
	for(int i = 2;i <= r;i++) {
		for(int j = 2;j <= c;j++) {
			int ans = 0;
			if(k[i - 1][j - 1]) {
				ans++;
			}
			if(k[i - 1][j]) {
				ans++;
			}
			if(k[i][j - 1]) {
				ans++;
			}
			if(k[i][j]) {
				ans++;
			}
			if(ans == 3) {
				printf("Bad placement.\n");
				return 0;
			}
		}
	}
	int ans = 0;
	for(int i = 1;i <= r;i++) {
		for(int j = 1;j <= c;j++) {
			if(k[i][j]) {
				ans++;
				queue<int>x,y;
				x.push(i);
				y.push(j);
				while(!x.empty()) {
					int x2 = x.front();
					int y2 = y.front();
					if(k[x2][y2 + 1]) {
						x.push(x2);
						y.push(y2 + 1);
						k[x2][y2 + 1] = 0;
					}
					if(k[x2 + 1][y2]) {
						x.push(x2 + 1);
						y.push(y2);
						k[x2 + 1][y2] = 0;
					}
					x.pop();
					y.pop();
				}
			}
		}
	}
	printf("There are %d ships.",ans);
	return 0;
}

信息

递交者
类型
递交
题目
P1012 海战
语言
C++
递交时间
2022-08-29 17:54:10
评测时间
2022-08-29 17:54:10
评测机
分数
100
总耗时
114ms
峰值内存
1.242 MiB