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. disabled和readonly区别

    disabled和readonly这两个属性有一些共同之处,比如都设为true,则form属性将不能被编辑,往往在写js代码的时候容易混合使用这两个属性,其实他们之间是有一定区别的: 如果一个输入项的 ...

  2. Springboot Download file

    @RequestMapping(value = "/downloadSvt") public ResponseEntity<FileSystemResource> ex ...

  3. 如何正确实现 Java 中的 HashCode

    相等 和 Hash Code 从一般角度来看,Equality 是不错的,但是 hash code 更则具技巧性.如果我们在 hash code上多下点功夫,我们就能了解到 hash code 就是用 ...

  4. c#读取文本并生成txt

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  5. Javascript中 toFixed

    javascript中toFixed使用的是银行家舍入规则. 银行家舍入:所谓银行家舍入法,其实质是一种四舍六入五取偶(又称四舍六入五留双)法. 简单来说就是:四舍六入五考虑,五后非零就进一,五后为零 ...

  6. 编程语言的分类及其优缺点,Python标准输入与输出

    一. 编程语言分类 1.机器语言 以0,1的组合作为指令集,用二进制指令来编写程序: 优点:执行效率高 缺点:开发效率低 2.汇编语言 用英文标签代替二进制指令集来编写程序,比机器语言稍微高级,但本质 ...

  7. int和string之间的转换

    #include<cstring> #include<algorithm> #include<stdio.h> #include<iostream> # ...

  8. 打开控制台F12弹出弹窗

    window.onload=function(){                 document.onkeydown=function(){                     var e=w ...

  9. selenium下打开Chrome报错解决

    错误如下: [22516:20196:0704/024642.979:ERROR:install_util.cc(597)] Unable to read registry value HKLM\SO ...

  10. linux nginx 基本用法

    nginx -s reload -p <nginx环境目录> -c <指定的配置文件> 其中-p -c 为可选,不写为默认路径和配置 在执行命令之前可通过 nginx -t - ...