求助,一个都过不了
查看原帖
求助,一个都过不了
759274
Stevehim楼主2022/9/10 18:16
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;

struct node {
	int a[11451] = {0};
} b[11451];

int book[11451] = {0};
int n;
int sum = 1;
int ma = 0;
void dfs(int x) { //咱也不知道是不是
//	cout << "x=" << x << " x+1=" << x + 1 << " b[x].a[x+1]=" << b[x].a[x + 1] << endl;
	while (b[x].a[x + 1] == 0 && book[x + 1] == 0) { //如果与下一个交点没有连接
		book[x + 1] = 1; //没有的话链接设为一
		x++; //下标加一
		sum++; //可能性加一
	}
	ma = max(sum, ma); //更新最大值
	sum = 1; //sum初始化
	return;
}

int main() {
	cin >> n; //输入n
	for (int i = 0; i < n; i++) { //将每个i与n的连接都设为1
		b[i].a[n] = 1; //设为一
	}
	int temp; //输入temp;
	for (int i = 0; i < n; i++) {
		cin >> temp;
		if (temp == 3) {
			for (int j = i + 1; j < n; j++) { //后面的点都标记上
//				cout << i << " " << j << endl;
				b[i].a[j] = 1; //标记与 这个点连接了
				b[j].a[i] = 1; //链接上的点也标记上

			}
		} else if (temp == 2) {
			for (int j = 0; j < i; j++) {
//				cout << i << " " << j << endl;
				b[i].a[j] = 1; //标记与这个点连接了
				b[j].a[i] = 1; //连接的点同样做一个记录
			}
		}
	}
	//输入完毕开始寻找
//	cout << "start to find" << endl;
	for (int i = 0; i < n; i++) {
		if (book[i] == 0 && b[i].a[i + 1] == 0) { //如果这个点没有被访问并且没有与下一个点连
			book[i] = 1; //先把它设为1
//			cout << i << endl;
			dfs(i); //开始搜索
		}
	}
	cout << ma;
	return 0;
}

2022/9/10 18:16
加载中...