Codeforces 632F Magic Matrix 题解
来源:互联网 发布:从其他excel导入数据 编辑:程序博客网 时间:2024/06/05 07:10
题意
给你一个n阶矩阵,问是否满足下列条件,aij=aji,aii=0,aij≤max(aik,ajk)
思路
先做前两个条件的判断,如果需要判断第三个条件,可以使用bitset,按值从小到大插入,记录对于每一行有哪一位比现在的小,再看现在这个数的i和j,对第i行和第j行取交,如果不为空,就不符合条件,如果所有检查完都没问题就符合条件
代码
#include <cstdio>#include <bitset>#include <algorithm>using namespace std;int A[2501][2501];bitset<2501> bs[2501];typedef struct matrix{ int val; int x; int y;}matrix;bool cmp(matrix a,matrix b){ return a.val<b.val;}matrix mat[2501*2501];int main(){ int n,f,e; scanf("%d",&n); for(int i=0;i<n;i++) for(int j=0;j<n;j++) { scanf("%d",&A[i][j]); mat[i*n+j].val=A[i][j]; mat[i*n+j].x=i; mat[i*n+j].y=j; } f=0; for(int i=0;i<n;i++) if(A[i][i]!=0) { f=1; break; } if(f==1) printf("NOT MAGIC\n"); else { for(int i=0;i<n&&f==0;i++) for(int j=0;j<i;j++) if(A[i][j]!=A[j][i]) { f=1; break; } if(f==1) printf("NOT MAGIC\n"); else { sort(mat,mat+n*n,cmp); e=0; for(int i=0;i<n*n;i++) { while(e<n*n&&mat[e].val<mat[i].val) { bs[mat[e].x][mat[e].y]=1; bs[mat[e].y][mat[e].x]=1; e++; } if((bs[mat[i].x]&bs[mat[i].y]).any()) { f=1; break; } } if(f==1) printf("NOT MAGIC\n"); else printf("MAGIC\n"); } } return 0;}
阅读全文
0 0
- Codeforces 632F Magic Matrix 题解
- codeforces 632F. Magic Matrix (最小生成树)
- CF 632F Magic Matrix
- [最小生成树] Codeforces 632F Educational Codeforces Round 9 F. Magic Matrix & SRM 687 div1 AllGraphCuts
- CF 632F(Magic Matrix-MST)
- CodeForces 327C Magic Five 题解&代码
- CodeForces 589F Gourmet and Banquet 题解
- Codeforces 598F Cut Length 题解
- 【线段树】[CodeForces - 717F]Heroes of Making Magic III
- Codeforces 803A Maximal Binary Matrix 题解
- codeforces 632F
- CodeForces 632F
- Codeforces-903F Clear The Matrix(状压DP)
- SEU寒假训练题解二 F Codeforces 441B
- 【Codeforces 808F】【网络流】Card Game 题解
- Codeforces Round #442 (Div. 2) 题解(877A~F)
- Codeforces632F Magic Matrix
- codeforces632F Magic Matrix -- bitset
- Java中的内部类
- Linux命令行,循环执行shell命令
- 人脸识别方向论文笔记(1)-- A Light CNN for Deep Face Representation With Noisy Labels
- python3进阶学习总结——安装PyMySQL
- IntelliJ IDEA的注册机及tomcat配置
- Codeforces 632F Magic Matrix 题解
- 20170601メモbaijiahao
- CentOS下让Apache支持.htaccess伪静态文件方法
- CSS 元素隐藏 滑动门 精灵图
- JavaScript 浏览器
- QT下的base的加密
- Android-沉浸状态栏
- 基于echars的图像绘制
- 深入hibernate的三种状态