为啥洛谷不识别count这个函数啊
查看原帖
为啥洛谷不识别count这个函数啊
426607
Blackeyenoob楼主2021/6/17 19:12
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
const int MAX = 2e3;
char map[MAX][MAX];
int vis[MAX][MAX];
int dir[8][2] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1} };
int n, m;
int step = 0;
int num[MAX*MAX];
int nmax = 0;
set<int> cnt;
vector<int> q;
void DFS(int x,int y);
int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> map[i][j];
			if (map[i][j] == '*') vis[i][j] = 1;
		}
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (vis[i][j]) {
				DFS(i, j);
				cnt.insert(step + 1);
				q.push_back(step + 1);
				step = 0;
			}
		}
	}

	for (auto a : cnt) {
		nmax = std::max(nmax, (a * count(q.begin(), q.end(), a)));
	}

	cout << cnt.size() << " " << nmax;
	return 0;
}
void DFS(int x,int y) {
	
	vis[x][y] = 0;
	for (int i = 0; i < 8; i++) {
		int tx = x + dir[i][0];
		int ty = y + dir[i][1];
		if (vis[tx][ty] && tx >= 1 && ty >= 1 && tx <= n && ty <= m) {
			DFS(tx, ty);
			step++;
		}
	}
}
2021/6/17 19:12
加载中...