首页 > 代码库 > Codeforces Round #420 A

Codeforces Round #420 A

Okabe and Future Gadget Laboratory

题意:给一个矩阵,如果矩阵中任意一个不为1的数都满足 存在一对 s t 使得 ais+atj=aij

思路:xjb暴力写

AC代码:

#include "iostream"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map"
#include "algorithm"
#include "stdio.h"
#include "math.h"
#define ll long long
#define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
#define mem(a) memset(a,0,sizeof(a))
using namespace std;
const int N=1e5+100;
int a[55][55],n;
int check(int l,int r){
    for(int i=1; i<=n; ++i){
        for(int j=1; j<=n; ++j){
            if(a[l][i]+a[j][r]==a[l][r])
                return 1;
        }
    }
    return 0;
}
int main(){
    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){
        for(int j=1; j<=n; ++j){
            if(a[i][j]!=1){
                if(!check(i,j)){
                    cout<<"No";
                    return 0;
                }
            }
        }
    }
    cout<<"Yes";
    return 0;
}
/*
3
1 1 2
2 3 1
6 4 1
3
1 5 2
1 1 1
1 2 3
*/

 

Codeforces Round #420 A