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 ...
随机推荐
- java 错误
ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2 解决在程序最后加一条语句system. ...
- 1 CRM
一.crm介绍 CRM,客户关系管理系统(Customer Relationship Management).企业用CRM技术来管理与客户之间的关系,以求提升企业成功的管理方式,其目的是协助企业管理销 ...
- Spring Boot文档维护:集成Swagger2
一.Swagger简介 在日常的工作中,我们往往需要给前端(WEB端.IOS.Android)或者第三方提供接口,这个时我们就需要提供一份详细的API说明文档.但维护一份详细的文档可不是一件简单的事情 ...
- Linux安装配置JDK1.7
1 在/usr/local 文件夹下新建一个文件夹software ,将JDK放到此文件夹中 并在此文件夹下解压执行命令 tar zxvf jdk-8u144-linux-x64.tar. ...
- 3、支付结果 /items/result?point=1&orderNo=201903211035400001
<template> <div> <div class="toppic"> <img src="../../../assets/ ...
- MFC笔记2
1.Create()函数创建,该函数原型如下: BOOL Create( LPCTSTR lpszCaption, DWORD dwStyle, const RECT& rect, CWnd* ...
- 使用pandas进行数据预处理01
数据预处理有四种技术:数据合并,数据清洗,数据标准化,以及数据转换. 数据合并技术:(1)横向或纵向堆叠合数据 (2)主键合并数据 (3)重叠合并数据 1.堆叠合并数据: 堆叠就是简单的把两个表拼接在 ...
- cdnbest配置强制ssl跳转
如何配置强制ssl跳转 1. 登陆用户站点,点击下图图标: 2. 如下图添加证书和开启强制ssl即可 hsts解释和作用: 国际互联网工程组织IETF正在推行一种新的Web安全协议HTTP Stric ...
- extJs学习的资源
http://www.qeefee.com/zt-extjs Ext JS 6 入门学习资料大全(2016-12-14) cddnExtJS学习:http://blog.csdn.net/co ...
- nginx实现http www服务的方式