B. StORage room (位运算结论可记住:一个数组,a[i] | a[j]得到一个n*n的矩阵,求这个数组,用pow(2,30)-1 & 矩阵的第i行得到一个数即为这个数组的第i个)

题目:   https://codeforces.com/contest/1903/problem/B

思想:

其中2^30-1的二进制为1111111...... 

代码:

// Problem: B. StORage room
// Contest: Codeforces - Codeforces Round 912 (Div. 2)
// URL: https://codeforces.com/contest/1903/problem/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 2e3+5;

ll n,a[N][N];
ll f[N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);

	int T;
	cin>>T;
	while(T--){
		cin>>n;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				cin>>a[i][j];
			}
		}
		for(int i=1;i<=n;i++){
			f[i]=pow(2,30)-1;
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if(i!=j){
					f[i]=(f[i]&a[i][j]);
				}
			}
		}
		bool flag=1;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if(i==j) continue;
				if((f[i]|f[j])!=a[i][j]){
					flag=false;
					break;
				}
			}
		}
		if(flag==false){
			cout<<"NO"<<"\n";
		} 
		else{
			cout<<"YES"<<"\n";
			for(int i=1;i<=n;i++){
				cout<<f[i]<<" ";
			}
			cout<<"\n";
		}
	}
	
	return 0;	

}

//1 11 10 101

  • 12
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值