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. windows下安装Scrapy框架

    一 首先我们通过pycharm安装: 发现不行,会报错. 二 通过命令行再次进行安装: 发现还是会报错: 更新下pip,继续安装,发现还是不行,那怎么办呢? 继续安装Scrapy发下还是不行: 那么我 ...

  2. springboot常见 10问

    1.什么是Spring Boot? 多年来,随着新功能的增加,spring变得越来越复杂.只需访问https://spring.io/projects页面,我们就会看到可以在我们的应用程序中使用的所有 ...

  3. MySQL 存储修改

    真的坑.

  4. Linq(高级查询)

    一.条件查 public List<Users> ss(string ids) { List<Users> ulist=new List<Users>(); 声明使 ...

  5. leetcode19

    class Solution { public: ; ; ListNode* removeNthFromEnd(ListNode* head, int n) { ; ListNode* node = ...

  6. echart 单选legend 并排序

    java代码 List<Map<String, Object>> AllList = null; JSONArray jsonArray = JSONArray.fromObj ...

  7. openwrt从18.0.1降级回到17.0.6遇到的问题

    因为觉得openwrt的18的配置检查功能很费时,特别是遇到ar93xx慢的真可以,所以决定从18.0.1降回到17.0.6上 先把18.0.1的配置backup出来,然后刷17.0.6,再把back ...

  8. servlet3.1

    Servlet3.1新增的新特性强制更改sessionId 由HttpServletRequest 的changeSessionId()方法实现 非阻塞式IO 非阻塞式IO我们应该知道Servlet底 ...

  9. Element-UI使用指南

    原网址:https://blog.csdn.net/u012285967/article/details/53023825 Element-UI是饿了么前端团队推出的一款基于Vue.js 2.0 的桌 ...

  10. layui-tree创建下拉树型选项框

    1.简介 也许你对树菜单再熟悉不过了,然而你仍有可能更青睐layui的tree,它也许比以往你知道的任何一个类似的组件都更轻量.简单,你在享受许多功能的同时,甚至不用去记太多的参数. 另外,最大的重点 ...