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 ...
随机推荐
- SQL Server数据库---》基础
SQL Server:只是操作数据库的一个工具(这种工具,只是提供一个界面化的方式让用户方便操作数据库) 开启服务:点击:我的电脑(计算机)--管理--服务和应用程序--服务--开启SQL Serve ...
- [key]严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener(Spring配置异常)
详细错误为: 严重: Exception sending context initialized event to listener instance of class org.springframe ...
- ajax调用后台Java
//html部分 <input type='text' placeholder='用户名' id="username" name="username" c ...
- c语言中的制表符\t与空格
(本文不讨论制表符与空格缩进问题) 编程过程中,我们常常用多个空格或制表符分隔两个字符串,那么这两个在显示效果上有什么区别呢? 比较如下两行代码的输出效果 代码1: printf("1\t1 ...
- iphone:自定义UIAlertView
由于项目中有这样一个需求:需要在保存是弹出框选择保存的地点.选择UIAlertView来实现,但是要在UIAlertView中增加UISwitch的控件,这就需要自定义一个继承UIAlertView的 ...
- 车间任务不允许"每个装配件"超过100000
应用 Oracle Work in Progress 层 Level Function 函数名 Funcgtion Name WIP_WIPMRMDF 表单名 Form Name WIPMRMDF ...
- Nginx和Nginx+的比较(上)
Nginx和Nginx+的比较(上) 作者:chszs,未经博主允许不得转载.经许可的转载需注明作者和博客主页:http://blog.csdn.net/chszs 一.Nginx+介绍 Nginx和 ...
- perl 分析binlog 定位错误sql 思路
1. 获取需要的binlog 日志: [root@zjzc01 binlog]# mysqlbinlog --start-datetime='2016-08-01 00:00:00' --stop-d ...
- C语言入门(8)——形参与实参
对于带参数的函数,我们需要在函数定义中指明参数的个数和每个参数的类型,定义参数就像定义变量一样,需要为每个参数指明类型,并起一个符合标识符命名规则的名字.例如: #include <stdio. ...
- NOI2011 Day2
NOI2011 Day2 道路修建 题目描述:给出一棵树,求每条边的两边的端点数的差乘边权之和. solution: 题目可能描述得不太清楚,如图: 对于虚边,如果边权为10,两边的端点数之差为2,这 ...