https://codeforces.com/contest/1118/problem/C

在查找元素的时候,必须按4,2,1的顺序进行。因为,如果先找1,可能就把原来的4拆散了,然后再找4,就找不到了

#include<bits/stdc++.h>
using namespace std;
int ans[][];
int main(){
int n;
cin>>n;
map<int,int> mp;
int t;
for(int i=;i<n*n;i++){
cin>>t;
mp[t]++;
}
vector<pair<int,pair<int,int> > > ceil;
for(int i=;i<(n+)/;i++)
for(int j=;j<(n+)/;j++){
if(i!=n--i&&j!=n--j)
ceil.push_back({,{i,j}});
else if(i!=n--i||j!=n--j)
ceil.push_back({,{i,j}});
else
ceil.push_back({,{i,j}});
}
int number[]={,,};
for(int q=;q<;q++){
int w=number[q];
for(int v=;v<ceil.size();v++){
pair<int,pair<int,int> > c=ceil[v];
int times=c.first;
if(times!=w)
continue;
int i=c.second.first;
int j=c.second.second;
map<int,int>::iterator it;
for(it=mp.begin();it!=mp.end();it++){
if(it->second>=times){
it->second-=times;
ans[i][j] = ans[n - i - ][j] = ans[i][n - j - ] = ans[n - i - ][n - j - ] = it->first;
break;
}
}
if(it==mp.end()){
cout<<"NO"<<endl;
return ;
}
}
}
cout<<"YES"<<endl;
for(int i=;i<n;i++){
for(int j=;j<n;j++){
cout<<ans[i][j]<<" ";
}
cout<<endl;
}
return ;
}

Codeforces Round #540 (Div. 3)--1118C - Palindromic Matrix的更多相关文章

  1. Codeforces Round #540 (Div. 3) C. Palindromic Matrix 【暴力】

    任意门:http://codeforces.com/contest/1118/problem/C C. Palindromic Matrix time limit per test 2 seconds ...

  2. Codeforces Round #540 (Div. 3) C. Palindromic Matrix (大模拟)

    题意:给你\(n\)个数,判断是否能构成一个\(n\)X\(n\)的回文矩阵,若可以,输出\(YES\)和矩阵,否则输出\(NO\). 题解:如果这个矩阵的行/列元素是偶数的话,很好办,所有出现的数一 ...

  3. Codeforces Round #540 (Div. 3) 部分题解

    Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...

  4. 二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix

    题目传送门 /* 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 */ #include <cstdio> #include < ...

  5. Codeforces Round #540 (Div. 3) A,B,C,D2,E,F1

    A. Water Buying 链接:http://codeforces.com/contest/1118/problem/A 实现代码: #include<bits/stdc++.h> ...

  6. Codeforces Round #531 (Div. 3) F. Elongated Matrix(状压DP)

    F. Elongated Matrix 题目链接:https://codeforces.com/contest/1102/problem/F 题意: 给出一个n*m的矩阵,现在可以随意交换任意的两行, ...

  7. Codeforces Round #540 (Div. 3)--1118F1 - Tree Cutting (Easy Version)

    https://codeforces.com/contest/1118/problem/F1 #include<bits/stdc++.h> using namespace std; in ...

  8. Codeforces Round #540 (Div. 3)--1118D2 - Coffee and Coursework (Hard Version)

    https://codeforces.com/contest/1118/problem/D2 和easy version的主要区别是,数据增加了. easy version采用的是线性查找,效率低 在 ...

  9. Codeforces Round #540 (Div. 3)--1118D1 - Coffee and Coursework (Easy version)

    https://codeforces.com/contest/1118/problem/D1 能做完的天数最大不超过n,因为假如每天一杯咖啡,每杯咖啡容量大于1 首先对容量进行从大到小的排序, sor ...

随机推荐

  1. 8-安装Kafka

    1.解压 tar -zxvf kafka_2.11-0.9.0.1.tar -C /opt/app/ 2.改权限 chown -R hadoop:hadoop /opt/app/ 3.修改配置文件 c ...

  2. 关于x-shell连接不上本地虚拟机linux

    首先把虚拟机网络模式调成nat模式,用于共享主机的ip地址. 然后再虚拟机输入命令ifconfig查看虚拟机的ip 在windows下ping一下虚拟机的ip确保能ping通,同理在虚拟机下ping主 ...

  3. 低级sql语法错误: BadSqlGrammarException

    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:760) at org.springf ...

  4. 【FZSZ2017暑假提高组Day1】最大矩形

    [问题描述] 现在有n个宽度为1的矩形按如下图(左边的)所示的方式排在了一起: 用肉眼容易看出,在左图内部面积最大的矩形如右图绿色部分所标注. 现在我们考虑将其中一些宽度为1的矩形取出,按照原顺序再次 ...

  5. K8s部署使用CFSSL创建证书

    证书的编码格式 PEM(Privacy Enhanced Mail),通常用于数字证书认证机构(Certificate Authorities,CA),扩展名为.pem, .crt, .cer, 和  ...

  6. Python介绍与安装

    Python 是一种面向对象的解释型程序设计语言,支持支持面向过程.函数式和面向对象编程.另外,Python可以在Windows.UNIX等多个操作系统上使用. 为什么学编程 编程是一种工具,可以实现 ...

  7. 洛谷P1169 棋盘制作(悬线法)

    题目链接:https://www.luogu.org/problemnew/show/P1169 #include<bits/stdc++.h> #define fi first #def ...

  8. Scrollview包裹布局问题。

    输入框获取焦点,键盘弹出,背景图片上移: https://blog.csdn.net/wljian1/article/details/79962802 android:scrollbarThumbVe ...

  9. TypeError: while_loop() got an unexpected keyword argument 'maximum_iterations'

    错误: TypeError: while_loop() got an unexpected keyword argument 'maximum_iterations' 参照https://blog.c ...

  10. mysql学习笔记--数据库单表查询

    一.查询语句 1.  select [选项] 列名 [from 表名]  [where 条件]  [order by 排序]  [group by 分组]  [having 条件]  [limit 限 ...