Codeforces Round #540 (Div. 3)--1118C - Palindromic Matrix
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的更多相关文章
- Codeforces Round #540 (Div. 3) C. Palindromic Matrix 【暴力】
任意门:http://codeforces.com/contest/1118/problem/C C. Palindromic Matrix time limit per test 2 seconds ...
- Codeforces Round #540 (Div. 3) C. Palindromic Matrix (大模拟)
题意:给你\(n\)个数,判断是否能构成一个\(n\)X\(n\)的回文矩阵,若可以,输出\(YES\)和矩阵,否则输出\(NO\). 题解:如果这个矩阵的行/列元素是偶数的话,很好办,所有出现的数一 ...
- Codeforces Round #540 (Div. 3) 部分题解
Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...
- 二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix
题目传送门 /* 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 */ #include <cstdio> #include < ...
- 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> ...
- Codeforces Round #531 (Div. 3) F. Elongated Matrix(状压DP)
F. Elongated Matrix 题目链接:https://codeforces.com/contest/1102/problem/F 题意: 给出一个n*m的矩阵,现在可以随意交换任意的两行, ...
- 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 ...
- Codeforces Round #540 (Div. 3)--1118D2 - Coffee and Coursework (Hard Version)
https://codeforces.com/contest/1118/problem/D2 和easy version的主要区别是,数据增加了. easy version采用的是线性查找,效率低 在 ...
- Codeforces Round #540 (Div. 3)--1118D1 - Coffee and Coursework (Easy version)
https://codeforces.com/contest/1118/problem/D1 能做完的天数最大不超过n,因为假如每天一杯咖啡,每杯咖啡容量大于1 首先对容量进行从大到小的排序, sor ...
随机推荐
- 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 ...
- VUE图片懒加载-vue lazyload插件的简单使用
序:vue项目时候,我们要对图片进行懒加载处理,这个开发项目中就不需要自己去写了,因为比较方便使用vue lazyload进行处理,高效率开发 一. vue lazyload插件: 插件地址:http ...
- python学习快人一步,从19个语法开始!
Python简单易学,但又博大精深.许多人号称精通Python,却不会写Pythonic的代码,对很多常用包的使用也并不熟悉.学海无涯,我们先来了解一些Python中最基本的内容. Python的特点 ...
- jQuery入门基础(动画效果)
一.隐藏显示 1.show()--显示隐藏的被选择元素 例:$(selector).show(speed,callback); 2.hide()--隐藏被选元素的内容 例:$(selector).hi ...
- 关于Haclon使用GPU加速的代码实例
关于Haclon使用GPU加速的代码实例 read_image(Image, 'T20170902014819_58_2_1.bmp') *没有加加速并行处理 count_seconds(T1) to ...
- Shell脚本1-20例
1.每天生成一个文件 描述:请按照这样的日期格式(xxxx-xx-xx)每日生成一个文件,例如今天生成的文件为)2017-07-05.log, 并且把磁盘的使用情况写到到这个文件中,(不用考虑cron ...
- tomcat 部署swagger 请求到后端乱码
问题: @ApiOperation(value = "", notes = "查看关键词列表") @ResponseBody @RequestMapping(v ...
- k8s定义Deployment,和service
定义一个Deployment和service做个简单的笔记 有时候我们需要开放Pod的多个端口,比如nginx的80和443端口,那如何定义Deployment文件呢,定义单个端口如下 apiVers ...
- 解决 jdk8 Illegal key size or default parameters 错误
网上搜到的答案如:https://blog.csdn.net/educast/article/details/81060085 大多是jdk1.6或1.7版本,有的jdk是1.8.99之前的版本,而 ...
- Ubuntu输入命令无效的问题
https://blog.csdn.net/u014797226/article/details/80800550?utm_source=blogxgwz2 Ubuntu启动时输入密码后,一直停留在登 ...