BestCoder Round #27 D

本文旨在为计算机科学爱好者提供从基础知识到高级概念的全面指南,覆盖编程语言、算法、数据结构、数据库理论、云计算、人工智能等核心领域。通过深入解析各类关键技术,帮助读者构建坚实的理论基础并提升实践能力。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近看ML看的晕,各种数学不会,特么的最优化就算了还泛函数,能虐死你啊,还是刷刷bc补充点能量比较好

#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
#include<bitset>
using namespace std;
#define i64 long long
#define foreach(c,itr)  for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define FOR(i,a,b)      for( int i = (a) ; i <= (b) ; i ++)
#define FF(i,a)         for( int i = 0 ; i < (a) ; i ++)
#define FFD(i,a,b)      for( int i = (a) ; i >= (b) ; i --)
#define S64(a)          scanf(in64,&a)
#define SS(a)           scanf("%d",&a)
#define LL(a)           ((a)<<1)
#define RR(a)           (((a)<<1)+1)
#define pb              push_back
#define pf              push_front
#define X               first
#define Y               second
#define CL(Q)           while(!Q.empty())Q.pop()
#define MM(name,what)   memset(name,what,sizeof(name))
#define MC(a,b)            memcpy(a,b,sizeof(b))
#define MAX(a,b)        ((a)>(b)?(a):(b))
#define MIN(a,b)        ((a)<(b)?(a):(b))
#define read            freopen("out.txt","r",stdin)
#define write            freopen("out2.txt","w",stdout)
#define lson l, m, rt << 1
#define rson m+1, r, rt << 1 | 1
#define MID ((l+r) >> 1)
#define lc rt << 1
#define rc rt << 1 | 1

const i64 inf64 = 0x2f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-9;
const double pi = acos(-1.0);
const int mod = 1000000007;
const int maxn = 101;

struct zz{
	int x;
	int y;
	int turn;
	const bool operator < (const zz & cmp) const{
		if (x != cmp.x){
			return x < cmp.x;
		}
		else{
			return y < cmp.y;
		}
	}
	const bool operator == (const zz & cmp) const{
		if (x == cmp.x && y == cmp.y) {
			return true;
		}
		else{
			return false;
		}
	}
}zx;

int n, m;
int f[maxn][maxn];
bool dp[maxn][maxn][2];

vector<zz>out[maxn][maxn];
int cnt[maxn][maxn];
vector<zz>in[maxn][maxn];
int Hash[maxn][maxn];

void bfs(){
	queue<zz>q;
	for (int x = 1; x <= n; x++){
		for (int y = 1; y <= n; y++){
			if (x < y){
				if (dp[x][y][0] == true){
					zx.x = x;
					zx.y = y;
					zx.turn = 0;
					q.push(zx);
				}
				if (cnt[x][y] == out[x][y].size()){
					dp[x][y][1] = true;
					zx.x = x;
					zx.y = y;
					zx.turn = 1;
					q.push(zx);
				}
			}
		}
	}
	zz now, to;
	while (!q.empty()){
		now = q.front();
		q.pop();
		if (now.turn == 0){
			for (int i = 0; i < in[now.x][now.y].size(); i++){
				to = in[now.x][now.y][i];
				cnt[to.x][to.y]--;
				if (cnt[to.x][to.y] == 0){
					dp[to.x][to.y][1] = true;
					to.turn = 1;
					q.push(to);
				}
			}
		}
		else{
			for (int i = 0; i < in[now.x][now.y].size(); i++){
				to = in[now.x][now.y][i];
				if (dp[to.x][to.y][0] == false){
					dp[to.x][to.y][0] = true;
					to.turn = 0;
					q.push(to);
				}
			}
		}
	}
}

bool start(){
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			in[i][j].clear();
			out[i][j].clear();
			cnt[i][j] = 0;
			dp[i][j][0] = false;
			dp[i][j][1] = false;
			Hash[i][j] = 0;
		}
	}	
	
	for (int i = 1; i <= m; i++){
		for (int x = 1; x <= n; x++){
			for (int y = 1; y <= n; y++){
				if (x<y)
				if (f[i][x] == f[i][y]){
					dp[x][y][0] = true;
					dp[y][x][0] = true;
				}
			}
		}
	}
	zz now, to;

	int hashcnt = 0;
	for (now.x = 1; now.x <= n; now.x++){
		for (now.y = 1; now.y <= n; now.y++){
			if (now.x < now.y){
				hashcnt++;
				for (int i = 1; i <= m; i++){
					to.x = f[i][now.x];
					to.y = f[i][now.y];
					if (to.x > to.y){
						swap(to.x, to.y);
					}
					if (to.x != to.y){
						if (Hash[to.x][to.y] != hashcnt){
							Hash[to.x][to.y] = hashcnt;
							cnt[now.x][now.y]++;
							in[to.x][to.y].push_back(now);
						}
					}
				}
			}
		}
	}
	
	bfs();

	for (int x = 1; x <= n; x++){
		for (int y = 1; y <= n; y++){
			if (x < y){
				if (dp[x][y][0] == false){
					return false;
				}
			}
		}
	}
	return true;

}

int  main(){
	int T;
	cin >> T;
	while (T--){
		cin >> n >> m;
		for (int i = 1; i <= m; i++){
			for (int j = 1; j <= n; j++){
				//cin >> f[i][j];
				SS(f[i][j]);
			}
		}
		if (start()){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值