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

3步!Spring Boot+OCR引擎秒提身份证/营业执照?手把手教你从零实现! OCR技术革新文档识别效率 本文演示了如何利用Spring Boot+Tesseract OCR+OpenCV构建自动化文档识别系统。相比传统人工录入,OCR技术可实现: 5秒极速提取身份证/营业执照关键信息 精准识别中文文本(准确率90%+) 正则过滤自动匹配结构化数据 技术要点: OpenCV图像预处理(灰度化+二值化) Tesseract多语言OCR识别 正则表达式精准提取证件号码 效率提升达100倍,错误率降低90%,适用于金融、政务等需要批量处理证件的场景。 阅读详情

任意门:http://codeforces.com/contest/1118/problem/C

C. Palindromic Matrix

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed.

For example, the following matrices are palindromic:

The following matrices are not palindromic because they change after the order of rows is reversed:

The following matrices are not palindromic because they change after the order of columns is reversed:

You are given n2n2 integers. Put them into a matrix of nn rows and nn columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic. If there are multiple answers, print any. If there is no solution, print "NO".

Input

The first line contains one integer nn (1≤n≤201≤n≤20).

The second line contains n2n2 integers a1,a2,…,an2a1,a2,…,an2 (1≤ai≤10001≤ai≤1000) — the numbers to put into a matrix of nn rows and nn columns.

Output

If it is possible to put all of the n2n2 numbers into a matrix of nn rows and nn columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic, then print "YES". Then print nn lines with nn space-separated numbers — the resulting matrix.

If it's impossible to construct any matrix, then print "NO".

You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.

Examples
input
Copy
4
1 8 8 1 2 2 2 2 2 2 2 2 1 8 8 1
output
Copy
YES
1 2 2 1
8 2 2 8
8 2 2 8
1 2 2 1
input
Copy
3
1 1 1 1 1 3 3 3 3
output
Copy
YES
1 3 1
3 1 3
1 3 1
input
Copy
4
1 2 1 9 8 4 3 8 8 3 4 8 9 2 1 1
output
Copy
NO
input
Copy
1
10
output
Copy
YES
10 
Note

Note that there exist multiple answers for the first two examples.

 

 

题意概括:

用一串序列构造一个回文方阵。

 

解题思路:

纯暴力。。。蜜汁bug;

做法很显然啊,分奇偶;

N为偶数的情况,直接按照策略四个四个构造即可,不存在解的情况就是出现不能被 4 整除的情况(上下左右要对称嘛);

N为奇数的情况,首先把最中间那个填了,找 出现次数为奇数的数即可。

然后也是先按照策略四个四个构造;

最后在两个两个构造,把中间那个十字部分填满。

想法很simple,bug很崩溃。。。

 

AC code:

  1 #include <bits/stdc++.h>
  2 #define INF 0x3f3f3f3f
  3 #define LL long long
  4 using namespace std;
  5 const int MAXN = 1e3+10;
  6 int sum[MAXN];
  7 int ans[50][50];
  8 int n, num;
  9 
 10 int main()
 11 {
 12     scanf("%d", &n);
 13     int N = n*n, x;
 14     for(int i = 1; i <= N; i++){
 15         scanf("%d", &x);
 16         sum[x]++;
 17     }
 18     int flag = true;
 19     int mid = (n+1)/2;
 20     int num = 1;
 21     if(n%2 == 0){
 22         for(int i = 1; i <= mid; i++){
 23             for(int j = 1; j <= mid; j++){
 24                 for(; num <= 1000; num++){
 25                     if(sum[num]){
 26                         if(sum[num]%4){
 27                             flag = false;
 28                             break;
 29                         }
 30                         ans[i][j] = ans[i][n-j+1] = ans[n-i+1][j] = ans[n-i+1][n-j+1] = num;
 31                         sum[num]-=4;
 32                         break;
 33                     }
 34                 }
 35                 if(num > 1000) flag = false;
 36                 if(!flag) break;
 37             }
 38             if(!flag) break;
 39         }
 40     }
 41     else{
 42         flag = true;
 43         num = 1;
 44         for(; num <= 1000; num++){
 45             if(sum[num]%2){
 46                 ans[mid][mid] = num;
 47                 sum[num]--;
 48                 break;
 49             }
 50         }
 51         if(num > 1000){
 52             flag = false;
 53             //puts("zjy");
 54         }
 55         else{
 56             num = 1;
 57             for(int i = 1; i < mid; i++){
 58                 for(int j = 1; j < mid; j++){
 59                     for(; num <= 1000; num++){
 60                         if(sum[num] == 0) continue;
 61                         if(sum[num]/4 < 1) continue;
 62                         ans[i][j] = ans[i][n-j+1] = ans[n-i+1][j] = ans[n-i+1][n-j+1] = num;
 63                         sum[num]-=4;
 64                         break;
 65                     }
 66                     if(num > 1000) flag = false;
 67                     if(!flag) break;
 68                 }
 69                 if(!flag) break;
 70             }
 71 
 72             num = 1;
 73             for(int i = 1; i < mid; i++){
 74                 for(; num <= 1000; num++){
 75                     if(sum[num]/2 >= 1){
 76                         ans[mid][i] = ans[mid][n-i+1] = num;
 77                         sum[num]-=2;
 78                         break;
 79                     }
 80                 }
 81                 if(num > 1000){flag = false; break;}
 82             }
 83 
 84             num = 1;
 85             for(int i = 1; i < mid; i++){
 86                 for(; num <= 1000; num++){
 87                     if(sum[num]/2 >= 1){
 88                         ans[i][mid] = ans[n-i+1][mid] = num;
 89                         sum[num]-=2;
 90                         break;
 91                     }
 92                 }
 93                 if(num > 1000){flag = false; break;}
 94             }
 95         }
 96     }
 97 
 98     if(!flag) puts("NO");
 99     else{
100         puts("YES");
101         for(int i = 1; i <= n; i++){
102             for(int j = 1; j <= n; j++)
103                 printf("%d ", ans[i][j]);
104             puts("");
105         }
106     }
107 
108     return 0;
109 }
View Code

 

计算机控制技术及应用 《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。 立即下载

相关推荐

第二十届全国大学生智能汽车竞赛极速光电组:MicroPython与恩智浦RT1021的硬件编程实战指南

本文为参加第二十届全国大学生智能汽车竞赛极速光电组的同学提供了一份详尽的MicroPython与恩智浦RT1021硬件编程实战指南。文章深入剖析了选择MicroPython与RT1021这对组合的优势,详细讲解了从开发环境搭建、基础硬件控制(如GPIO、PWM、编码器、CCD)到系统集成(平衡控制、循迹算法)与多任务调试的全过程,旨在帮助参赛者降低嵌入式开发门槛,高效备赛。

wdx0123456的博客 846

C. Palindromic Matrix(codeforces)

Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed. For e...

蒟蒻小胖 575

FineBI制作数据可视化大屏-数据连接(1)

快速上手大屏可视化,FineBI数据连接配置。

Pangaoyang_的博客 1915

codeforces1118c

C. Palindromic Matrix time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Let's call some square matrix with integer values in its ce...

PL博客 317

C++ muduo网络库知识分享01 - Linux平台下muduo网络库源码编译安装

Muduo is a multithreaded C++ network library based on the reactor pattern. muduo库的介绍就是:一个基于reactor反应堆模型的多线程C++网络库。 muduo网络库是C++语言开发的一个非常优秀的网络库,作者陈硕,muduo网络库在多线程环境下性能非常高,该系列文章会分享一些muduo库源码的知识,包括它的线程池源码...

大秦坑王的专栏 3万+

基于多智能体深度强化学习的空地协同通信系统轨迹设计与访问控制

所属子方向: UAV assisted communication 名词注释 coordinated:协调、协同 base stations 基站,公用移动通信基站,是移动设备接入互联网的接口设备,是指在一定的无线电覆盖区中,通过移动通信交换中心,与移动电话终端之间进行信息传递的无线电收发信电台。 UAV-BS:无人机基站 cooperative-competitive game:合作竞争博弈 throughput :吞吐量,每秒比特数 bps,bits per second Determinis

skysys的研究小屋 4969

Codeforces Round #540 (Div. 3) C.Palindromic Matrix

http://codeforces.com/contest/1118/problem/C 题意就是给n2n^2n2个数,填成一个上下左右都对称的矩阵。 submission #include&lt;queue&gt; #include&lt;cstdio&gt; #include&lt;cstdlib&gt; #include&lt;iostream&gt; #include&lt;string&...

侯山窝矿工 242

手机流畅的秘密:拆解LPDDR5X在骁龙8 Gen2平台上的电源与信号完整性设计

本文深入解析了LPDDR5X内存与骁龙8 Gen2处理器在旗舰手机中的协同设计,重点探讨了0.5V超低电压下的电源完整性设计以及8.5Gbps高速传输中的信号完整性挑战。通过详细的电源树架构、关键器件选型和布线策略分析,揭示了如何实现高性能与低功耗的完美平衡,为手机流畅体验提供硬件保障。

weixin_30235225的博客 484

C. Palindromic Matrix

 http://codeforces.com/contest/1118/problem/C 题意:给n(0-20),和n*n数组,构造n*n回文数组,行和列调换不变 思路:n为偶时,必然每个数时4的倍数;奇时个数为奇数的一个是最中间,中间行和列两两构造,剩下的四个四个构造; #include&lt;algorithm&gt; #include&lt;set&gt; #include&lt;...

newhonor 497

【Android Performance】Android CPU绑核实战:从taskset到cpuset的完整调优指南

本文系统讲解Android系统中的CPU绑核(CPU Affinity)技术,涵盖用户空间的taskset命令行绑核、内核cpuset分组机制的原理与操作、进程级与线程级绑核的代码实现、以及中断绑核的底层方法。文中深入拆解CPU亲和性掩码的计算规则、各cpuset分组的默认策略差异、绑核后的验证手段及常见踩坑场景,并配有多项实操命令与C代码示例。适合从事Android系统性能调优、进程调度优化的开发者阅读。

weixin_44081096的博客 1312

30天入门 SAP BTP 开发系列之二:了解 SAP BTP Region 的概念,包含账号申请的详细步骤

SAP BTP 的 Region,实际是一组按地理位置划分的、由 SAP 或合作 Hyperscaler 承载的基础设施栈。这些基础设施栈至少包含多可用区网络、对象存储、计算节点及自动化运维等服务。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1469

Codeforces Round #540 (Div. 3)

比赛状态奇差无比 (solved 2/8),CD两题疯狂WA。 文章目录A.Water BuyingB.Tanya and Candies题意题解代码C.Palindromic Matrix题意题解代码D.Coffee and Coursework题意题解代码F.Tree Cutting (Easy Version)题目题解代码 A.Water Buying 大水题,pass /*** au...

zxwsbg的博客 352

成本中心(CO)和利润中心(PCA)是管理会计模块的核心组件

SAP中成本中心(CO)和利润中心(PCA)凭证处理存在差异:①外部交易(如费用支付、销售)会生成FI借贷凭证;②内部成本分摊和转移仅产生CO/PCA管理凭证,通过次级成本要素或利润中心转移科目记录,不涉及FI模块。核心区别在于是否涉及企业实际收支:实际收支触发FI凭证,内部核算仅生成管理会计凭证。系统通过这种机制实现财务会计与管理会计的集成与分离。

金牌架构师 1128

CodeForces - 1118C Palindromic Matrix 构造 优先队列

Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed. For e...

还我笑颜 446

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

C. Palindromic Matrix(构造,模拟)

自己画图就发现可以分为n偶数和奇数自己画图就发现可以分为n偶数和奇数自己画图就发现可以分为n偶数和奇数 n偶数,很好办,只需要4个4个放置就好了n偶数,很好办,只需要4个4个放置就好了n偶数,很好办,只需要4个4个放置就好了 n奇数,有些地方4个一组,有些地方2个一组,最中心1个1组n奇数,有些地方4个一组,有些地方2个一组,最中心1个1组n奇数,有些地方4个一组,有些地方2个一组,最中心1个1组 这时候怎么放?这时候怎么放?这时候怎么放? 我们先放4个一组的位置,再放2个一组,最后1个一组我们先放4个一组

jziwjxjd的博客 465

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Codeforces Round #540 (Div. 3) c题 (codeforce 1118c) Palindromic Matrix

C. Palindromic Matrix time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Let’s call some square matrix with integer values in its cells palindrom...

caowenbo2311694605的博客 435

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

[leetcode] 54. Spiral Matrix @ python

原题 Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. Example 1: Input: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Output: [1,2,3,6,9,8,7,4,5] Exam...

闲庭信步 516

codeforce 1118C Palindromic Matrix(模拟)

题意:给你n*n个数,让你构造一个n*n的回文矩阵。如果没答案输出NO。 思路:暴力构造一下,奇数填中间。代码稍长一些。 #include &lt;bits/stdc++.h&gt; using namespace std; typedef long long ll; int m[1005][1005];int a[1005]; int vis[1005]; int main() { in...

阿狸的博客 441

CF-C.Palindromic Matrix(回文方阵)

Input 4 1 8 8 1 2 2 2 2 2 2 2 2 1 8 8 1 Output YES 1 2 2 1 8 2 2 8 8 2 2 8 1 2 2 1 Input 3 1 1 1 1 1 3 3 3 3 Output YES 1 3 1 3 1 3 1 3 1 Input 4 1 2 1 9 8 4 3 8 8 3 4 8 9 2 1 1 Output NO Input 1 10 Output YES 10 -横竖都要回文数 #include <bits/stdc++.h> u..

xuhang513的博客 653

C - Palindromic Matrix

原题地址:http://code-festival-2017-quala.contest.atcoder.jp/tasks/code_festival_2017_quala_c Time limit: 2sec /Memory limit: 256MB Score :400points Problem Statement We have anH-by-Wma...

dianli6932的博客 261

Codeforces Round #540 (Div. 3) C. Palindromic Matrix 构造

题解 题目大意,给你n*n个数值,要求构造一个n阶对称方阵,方阵上下对称左右对称沿主对角线对称。 根据题目所给示例可以发现,n为偶数情况每个数值至少出现4次,n为奇数情况行坐标或列坐标为(n+1)/2时数值最少出现两次(标号从1开始),最中心位置数值最少出现一次。 根据规律进行构造即可。 AC代码 #include &lt;stdio.h&gt; #include &lt;bits/stdc++....

CaprYang的博客 637

Palindromic Matrix

Palindromic Matrix time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Let's call some square matrix with integer value...

weixin_30677475的博客 205

CF - 229C - 想法题

一个完全图中m条边属于Alice..剩下的属于Bob..求Alice和Bob分别用属于自己的边能得到的三角形个数之和..分开来想非常麻烦..似乎也没得办法..何不逆转思维..一个三角形若不属于Alice也不属于Bob..那么必然是其3条边中既有属于Alice的也有属于Bob的...称这种三角形为 不统计三角形.. 根据输入易得某点有多少属于Alice的边,记为k...进而算出其有多少属于

Julyana_Lin_夜 1130

Codeforces Round #540 (Div. 3)--C. Palindromic Matrix(构造题---回文方阵的构造)

Palindromic Matrix 题目链接http://codeforces.com/problemset/problem/1118/C time limit per test:2 seconds memory limit per test:256 megabytes Let’s call some square matrix with integer values in its cells ...

孤风的博客 603

leetcode Spiral Matrix 螺旋输出矩阵

Given the following matrix: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]] You should return [1,2,3,6,9,8,7,4,5]. 思路: 来看第一圈,行左到右-&amp;gt;列上到下-&amp;gt;行右到左-&amp;gt;列下到上, 后面一直重复,来四个游标定边界,left,right,up,down while终止条件:le...

acttell的博客 588

Codeforces Contest 1118 A-F 想法,二分,模拟,构造,dfs

A. Water Buying Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water. There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. ...

天翼之城的博客 785
上一篇: BZOJ 1878 [SDOI2009]HH的项链 【莫队】
下一篇: Codeforces Round #540 (Div. 3) D1. Coffee and Coursework (Easy version) 【贪心】
莜莫oO
博客等级 码龄9年 7粉丝 226原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值