codeforces 632F. Magic Matrix
给一个n*n的矩阵, 问是否对角线上的元素全都为0, a[i][j]是否等于a[j][i], a[i][j]是否小于等于max(a[i][k], a[j][k]), k为任意值。
前两个都好搞, 我们来看第三个。 第三个的意思是, 对于a[i][j], 它小于等于第i行和第j行每一列的两个元素的最大值。
我们将矩阵中的每一个元素的值以及x, y坐标都加到一个数组里面, 然后从小到大排序。 从0到n-1枚举每一个i, 如果一个元素pos比i小, 那么就将b[pos的x][pos的y]这个数组值置为1, 直到剩下的元素值都比i大。 然后我们查看b[i的x], b[i的y] 这两行, 如果这两行的某一列两个值同时为1, 那么说明不满足。
具体可以看代码, b数组可以用一个bitset来代替。
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = ;
bitset <maxn> b[maxn];
int a[maxn][maxn];
struct node
{
int x, y, val;
bool operator < (node a)const {
return val<a.val;
}
node(){}
node(int _x, int _y, int _val):x(_x), y(_y), val(_val){}
}q[maxn*maxn];
int main()
{
int n;
cin>>n;
for(int i = ; i<n; i++) {
for(int j = ; j<n; j++) {
scanf("%d", &a[i][j]);
}
}
for(int i = ; i<n; i++) {
if(a[i][i]) {
puts("NOT MAGIC");
return ;
}
}
for(int i = ; i<n; i++) {
for(int j = ; j<n; j++) {
if(a[i][j] != a[j][i]) {
puts("NOT MAGIC");
return ;
}
}
}
for(int i = ; i<n; i++) {
for(int j = ; j<n; j++) {
q[i*n+j] = node(i, j, a[i][j]);
}
}
sort(q, q+n*n);
int pos = ;
for(int i = ; i<n*n; i++) {
while(pos<n*n && q[pos].val<q[i].val) {
b[q[pos].x][q[pos].y] = ;
pos++;
}
if((b[q[i].x]&b[q[i].y]).any()) {
puts("NOT MAGIC");
return ;
}
}
puts("MAGIC");
return ;
}
codeforces 632F. Magic Matrix的更多相关文章
- Codeforces 632F Magic Matrix(bitset)
题目链接 Magic Matrix 考虑第三个条件,如果不符合的话说明$a[i][k] < a[i][j]$ 或 $a[j][k] < a[i][j]$ 于是我们把所有的$(a[i][j ...
- codeforces 632F. Magic Matrix (最小生成树)
You're given a matrix A of size n × n. Let's call the matrix with nonnegative elements magic if it i ...
- Codeforces 632F - Magic Matrix(暴力 bitset or Prim 求最小生成树+最小瓶颈路)
题面传送门 开始挖老祖宗(ycx)留下来的东西.jpg 本来想水一道紫题作为 AC 的第 500 道紫题的,结果发现点开了道神题. 首先先讲一个我想出来的暴力做法.条件一和条件二直接扫一遍判断掉.先将 ...
- Educational Codeforces Round 9 F. Magic Matrix 最小生成树
F. Magic Matrix 题目连接: http://www.codeforces.com/contest/632/problem/F Description You're given a mat ...
- CF 1042 E. Vasya and Magic Matrix
E. Vasya and Magic Matrix http://codeforces.com/contest/1042/problem/E 题意: 一个n*m的矩阵,每个位置有一个元素,给定一个起点 ...
- Vasya and Magic Matrix CodeForces - 1042E (概率dp)
大意:给定n*m矩阵, 初始位置(r,c), 每一步随机移动到权值小于当前点的位置, 得分为移动距离的平方, 求得分期望. 直接暴力dp的话复杂度是O(n^4), 把距离平方拆开化简一下, 可以O(n ...
- Codeforces 710C. Magic Odd Square n阶幻方
C. Magic Odd Square time limit per test:1 second memory limit per test:256 megabytes input:standard ...
- Codeforces 670D1. Magic Powder - 1 暴力
D1. Magic Powder - 1 time limit per test: 1 second memory limit per test: 256 megabytes input: stand ...
- [递推+矩阵快速幂]Codeforces 1117D - Magic Gems
传送门:Educational Codeforces Round 60 – D 题意: 给定N,M(n <1e18,m <= 100) 一个magic gem可以分裂成M个普通的gem ...
随机推荐
- 扩展第三方DropDownMenu
找工作之际,静下心总结工作中的想法. 我的简书 原来的效果 Paste_Image.png #解析结构 导读 想要扩展首先我需要执行下面几个步骤 1.fork DropDownMenu到自己的gith ...
- ios 中的构造方法
构造方法 1.什么是构造方法? 初始化对象的方法. 默认情况下,在 OC 当中创建1个对象分为两部分(new 做的事): +alloc:分配内存空间 -init :初始化对象 2.构造方法的作用是? ...
- OC中协议的概念以及用法
OC中协议的概念以及用法,协议也是OC中的一个重点,Foundation框架以及我们后面在写代码都会用到. OC中的协议就是相当于Java中的接口(抽象类),只不过OC中的名字更形象点,因为我们在学习 ...
- Maven 打包到Tomcat下
1.在tomcat/conf下tomcat-users.xml 文件下添加 <role rolename="manager"/> <user usern ...
- 超快速使用docker在本地搭建hadoop分布式集群
超快速使用docker在本地搭建hadoop分布式集群 超快速使用docker在本地搭建hadoop分布式集群 学习hadoop集群环境搭建是hadoop入门的必经之路.搭建分布式集群通常有两个办法: ...
- [LeetCode]题解(python):151-Reverse Words in a String
题目来源: https://leetcode.com/problems/reverse-words-in-a-string/ 题意分析: 给定一个字符串,里面包括多个单词,将这个字符串的单词翻转,例如 ...
- AutoIt 函数学习之----WinWaitActive
WinWaitActive函数 暂停脚本的执行直至指定窗口被激活(成为活动状态)为止. WinWaitActive ( "窗口标题"[, "窗口文本"[, 超时 ...
- 柯南君:看大数据时代下的IT架构(4)消息队列之RabbitMQ--案例(Helloword起航)
柯南君:看大数据时代下的IT架构(4)消息队列之RabbitMQ--案例(Helloword起航) 二.起航 本章节,柯南君将从几个层面,用官网例子讲解一下RabbitMQ的实操经典程序案例,让大家重 ...
- 浅析指针(pointer)与引用(reference)
在c++函数中,形式参数用引用和用指针都可以起到在被调用函数中改变调用函数的变量的作用.什么时候用引用作参数?什么时候用指针作参数呢 void function (int *ptr); void fu ...
- [LeetCode][Python]Longest Substring Without Repeating Characters
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest ...