Palindromic Matrix(构造法)-CodeForces div2 540C

小红书私信接口与Hook技术实战:微信跳转卡片的合规与破解之道 本文深入探讨了小红书私信接口与Hook技术的实战应用,重点解析了微信跳转卡片的合规使用与破解方法。通过官方私信接口的合规玩法与Xposed框架的Hook技术对比,为开发者提供了技术选型指南和实战建议,帮助实现高效的用户跳转与转化。 阅读详情

题目传送门
题意:
题目就是给你一组序列要你利用这些数构造出一个上下对称,左右也对称的n*n矩阵。若不能,输出NO,否则输出YES,并输出够早的矩阵。
思路:
比赛的时候,自己求快,稍微有点头目就开始动笔,不愿意继续深入归纳(自己有点懒)。结果就是调试爆炸,代码超长。写出了一个垃圾代码。
像这种构造体,或者模拟题,一定要去找到不同情况之间的共性。归纳他们的相同点和不同点。比如这里分为n为奇数和偶数两种情况。偶数简单,开始分成4块,用数字填写那对称的4块时,他们两个可以共用一些代码。
下面n为奇数时,要特别处理中间的,中间的至少要2个,中心1个。对称的4块要4个。
还有就是找数,可以用一个通用函数get_sum,不管找几个,只要找到后,就把相应的数的次数减去相应的个数,然后返回。找不到就返回NO的标记值。
自己的思维还是局限,没有养成抽象的习惯,总是翻译简单易懂的逻辑,没有用另一种稍微转一下弯的逻辑(旺旺可以简化代码,减低出错率)。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<string>
#include<cmath>

using namespace std;

typedef long long LL;

#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define per(i,a,b) for(int i = a;i <= b;++i)
#define rep(i,a,b) for(int i = a;i >= b;--i)
const int maxn = 20;
int n = 0,m = 0;
map<int,int> mp;
int a[maxn+10][maxn+10];
int get_num(int cnt){
	map<int,int>::iterator it = mp.begin();
	for(it = mp.begin();it != mp.end();++it){
		if(it->second >= cnt){
			it->second -= cnt;
			return it->first;
		}
	}
	return -1;
}
void solve(){
	per(i,1,n/2){//n为偶数和奇数都是用的情况 
		per(j,1,n/2){
			int num = get_num(4);
			if(num == -1){
				printf("NO\n");
				return ;
			}
			a[i][j] = a[n+1-i][j] = a[i][n+1-j] = a[n+1-i][n+1-j] = num;
		}
	}
	
	if(n & 1){//奇数要处理中间行和列 
		per(i,1,n/2){
			int num = get_num(2);
			if(num == -1){
				printf("NO\n");
				return ;
			}
			a[i][(n+1)/2] = a[n+1-i][(n+1)/2] = num;
			num = get_num(2);
			if(num == -1){
				printf("NO\n");
				return ;
			}
			a[(n+1)/2][i] = a[(n+1)/2][n+1-i] = num;
		}
		int num = get_num(1);
		if(num == -1){
				printf("NO\n");
				return ;
			}
		a[(n+1)/2][(n+1)/2] = num; 
	}
	printf("YES\n");
	per(i,1,n){
		per(j,1,n){
			printf("%d%c",a[i][j],j == n ? '\n' : ' ');
		}
	}
	
}
int main(){
	while(~scanf("%d",&n)){
		mp.clear();
		per(i,1,n*n){
			int x = 0;
			scanf("%d",&x);
			++mp[x];		
		}
		solve();
	}
	
	return 0;
}

垃圾AC代码(没有归纳好):

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<string>
#include<cmath>

using namespace std;

typedef long long LL;

#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define per(i,a,b) for(int i = a;i <= b;++i)
#define rep(i,a,b) for(int i = a;i >= b;--i)
const int maxn = 1e3;
int n = 0,m = 0;
//int times[maxn+10];
map<int,int> mp; 
int b[maxn+10];
int a[30][30];
void solve(){
	map<int,int>::iterator it = mp.begin();
	int num[maxn+10];
	int cnt = 0;
	if(n % 2 == 0){
		for(it = it;it != mp.end();++it){
			per(i,1,it->second / 4){
				num[++cnt] = it->first;
			}
		}
		int p = 0;
		per(i,1,n/2){
			per(j,1,n/2){
				a[i][j] = num[++p];
			}
		}
		per(i,1,n/2){
			per(j,n/2+1,n){
				a[i][j] = a[i][n+1-j];
			}
		}
		per(i,n/2+1,n){
			per(j,1,n){
				a[i][j] = a[n+1-i][j];
			}
		}
	}else{
		int center = 0;
		int np2[maxn+10];
		int cnt = 0,cnt2 = 0;
		for(it = mp.begin();it != mp.end();++it){
			if(it->second & 1){
				center = it->first;
				it->second -= 1;
			}
			if(it->second >= 4){
				per(i,1,it->second/4){
					num[++cnt] = it->first;
				}
			}
			if(it->second % 4 == 2 && it->second != 0){//不可能只有1这一个小于4的数 
				np2[++cnt2] = it->first; 
			}
		}
		//cout << "na " <<cnt <<" " <<cnt2 << endl;
		if(cnt2 > n-1 && n != 1){
			printf("NO\n");
			return ;
		}
		int mid = (n+1)/2;
		a[mid][mid] = center;
		int pos = 1;
		bool flag = false;
		per(i,1,cnt2){
			a[pos][mid] = a[n+1-pos][mid] = np2[i];
			++pos;
			if(pos == mid){
				flag = true;
				break;
			}
		}
		bool flag2 = false;
		int k = 1;
		if(flag == true){
			pos = 1;
			per(i,n/2+1,cnt2){
				a[mid][pos] = a[mid][n+1-pos] = np2[i];
				++pos;
				if(pos == mid){
					flag2 = true;
					break;
				}
			}
			int ps = 0;
			if(flag2 == false){
				//cout << "hah" << endl;
				for(k = 1;k <= cnt;){
					//cout << "nihao " << k << " " <<pos << endl;
					a[mid][pos] = a[mid][n+1-pos] = num[k];
					++pos;++ps;
					if(ps % 2 == 0){
						++k;
					}
					if(pos == mid){
						break;
					}
					a[mid][pos] = a[mid][n+1-pos] = num[k];
					++pos;++ps;
					if(ps % 2 == 0){
						++k;
					}
					if(pos == mid){
						break;
					}
				
				}
			}
		//	cout << "nima " <<k << " " <<cnt << endl;
		}else{
			//cout << "po " << pos <<" " <<k << " " <<cnt << " " << cnt2 <<endl;
 			int ps = 0;
			//cout << "niam " << pos << "" << k << endl;
			for(k = 1;k <= cnt;){
			//	cout << pos <<" ji " << num[k] << endl;
				a[pos][mid] = a[n+1-pos][mid] = num[k];
				++pos;++ps;
				if(ps % 2 == 0){
					++k;
				}
				if(pos == mid){
					break;
				}
				a[pos][mid] = a[n+1-pos][mid] = num[k];
				++pos;++ps;
				if(ps % 2 == 0){
					++k;
				}
				if(pos == mid){
					break;
				}
			}
			pos = 1;
			for(k = k;k <= cnt;){
				a[mid][pos] = a[mid][n+1-pos] = num[k];
				++pos;++ps;
				if(ps % 2 == 0){
					++k;
				}
				if(pos == mid){
					break;
				}
				a[mid][pos] = a[mid][n+1-pos] = num[k];
				++pos;++ps;
				if(ps % 2 == 0){
					++k;
				}
				if(pos == mid){
					break;
				}
			}
		}
		int p = k;
			per(i,1,n/2){
				per(j,1,n/2){
					//if(i == n/2){
					//	cout <<"ko " << p <<" " << num[p] << endl;
					//}
					a[i][j] = num[p++];
				}
			}
			per(i,1,n/2){
				per(j,n/2+1,n){
					a[i][j] = a[i][n+1-j];
				}
			}
			per(i,n/2+1,n){
				per(j,1,n){
					a[i][j] = a[n+1-i][j];
				}
			}
		
	}
	printf("YES\n");
	per(i,1,n){
		per(j,1,n){
			printf("%d%c",a[i][j],j == n ? '\n': ' ');
		}
	}
}
int main(){
	while(~scanf("%d",&n)){
		mp.clear();
		per(i,1,n*n){
			scanf("%d",&b[i]);
			++mp[b[i]];
		}
		map<int,int>::iterator it = mp.begin();
		if(n % 2 == 0){
			for(it = it;it != mp.end();++it){
				if(it->second % 4 != 0){
					printf("NO\n");
					return 0;
				}
			}
		}else{
			int flag = 0;
			for(it = mp.begin();it != mp.end();++it){
				if(it->second & 1){
					++flag;
					if(flag > 1){
						printf("NO\n");
						return 0;
					}
				}
			}
		}
		solve();
	}
	
	return 0;
}
主流仿真软件Sigrity/HFSS/Siwave/Hyperlynx/ADS差异 在电子设计自动化(EDA)领域,各种仿真软件如Cadence Sigrity、Mentor Graphics的HyperLynx、Keysight的ADS以及ANSYS的SIwave等,都广泛应用于不同的应用场景中。综上所述,这些EDA仿真软件在各自的应用场景中发挥着重要作用,帮助工程师在设计阶段就能够评估和优化电子产品的性能,提高设计的可靠性和效率。:Sigrity由全球最大的EDA公司Cadence推出,Cadence还推出了Orcad和Allegro等著名软件。:由安捷伦(现是德科技)公司开发。 阅读详情

相关推荐

论文阅读4——一种宽频带圆极化微带天线的设计

论文阅读——一种宽频带圆极化微带天线的设计(现在才觉得开始弄懂了一点,懂了一点之后又更糊涂了……)

weixin_64612422的博客 2319

CodeForces 1118C Palindromic Matrix

Palindromic Matrix time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Input The first line contains one integer n (1≤n≤20). The second line contains n2 integers a1,a2,…,an2 (1≤ai≤1000) — the numbers t

weixin_43823753的博客 237

Linux-BSP-WIFI驱动移植与调试实战——以RTL8189FS为例

本文以RTL8189FS为例,详细介绍了Linux BSP中WiFi驱动移植与调试的全流程。涵盖硬件原理图分析、内核配置、设备树适配、驱动编译加载及问题排查等关键步骤,提供实用的调试技巧和解决方案,帮助开发者高效完成嵌入式WiFi驱动开发。

moon9的博客 399

(Python实现)PAT 1019 General Palindromic Number (20 分)

1019 General Palindromic Number (20 分) A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers. 如果一个数字在向前或向后写的时

Vicky 277

电力电子技术(13)——大功率可控整流电路

目录引言2.6.1 带平衡电抗器的双反星形可控整流电路电路结构的特点接平衡电抗器的原因平衡电抗器使得两组三相半波整流电路同时导电的原理分析谐波分析2.6.2 多重化整流电路概述原理目标1)移相多重联结2)多重联结电路的顺序控制3重晶闸管整流桥顺序控制带平衡电抗器的双反星形可控整流电路(是多重化整流电路的重要形式之一)的特点:适用于低电压、大电流的场合。多重化整流电路的特点:绕组的极性相反的目的:消除直流磁通势如图所示,虽然两组相电流的瞬时值不同,但是平均电流相等而绕组的极性相反,所以直流安匝(电流*匝数)互

weixin_45589295的博客 1万+

OLED 驱动模块程序代码

作为嵌入式软件开发,可能经常会使用单片机连接驱动显示屏,实现人机交互的功能,通常可选择的有 OLED 和 LCD 等,其中相关驱动代码例程网上更是数不胜数。 本文介绍的是 OLED, 常见代表有 0.96 寸的OLED,网上也有很多相关的驱动代码,但是大部分代码都是能用即可,不是特别关注驱动代码的整体架构,以下是个人整理的 OLED 驱动代码,支持配置 SPI 和 IIC 两种接口方式(目前只是测试了 SPI,IIC 有待验证)。

大橙子的博客 4291

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

18.EC实战 新建项目工程并配置各个引脚的工作方式(持续更新)

本博文介绍了从零开始新建EC工程及对各个引脚进行了工作模式的初始化配置

qq_30135687的博客 1732

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

Unity3D实现项目限制功能(使用次数限制和时间限制)

大家好,我是心疼你的一切,不定时更新Unity开发技巧,觉得有用记得一键三连哦。在软件开发的时候,可能会遇到程序的使用次数限制,以及时间的限制,下面就写一下这两种方法是新建注册表,增加键值对,修改键值,完成对程序的控制提示:以下是本篇文章正文内容,下面案例可供参考以上就是讲了两种限制方法不定时更新Unity开发技巧,觉得有用记得一键三连哦。

心疼你的一切博客 1812

ros入门(八)---TF坐标转换

TF(TransForm),就是坐标转换,包括了位置和姿态两个方面的变换。

weixin_51157015的博客 3389

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

【异常】Python环境中没有安装 `openpyxl` 模块提示ModuleNotFoundError: No module named ‘openpyxl‘

是一个用于读写Excel 2010 xlsx/xlsm/xltx/xltm文件的库。只是示例版本号,你可以根据需要选择不同的版本。安装完成后,再次尝试运行你的程序,应该就不会再出现。,这表明你的Python环境中缺少。运行一个Python程序时遇到了。如果由于某些原因你无法直接使用。,你可以指定版本号来安装,这里。要解决这个问题,你需要安装。

奶爸的编程之路,也就一周冷个三天 3399

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

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

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

贪心、构造

ACoder 276

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

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

题目链接:http://codeforces.com/contest/1118/problem/C 题意:给你n*n个数,你要将这些数放到一个n阶矩阵里,要求矩阵上下左右对称,如果不行输出"NO",否者输出符合条件的矩阵。 解题心得: 刚开始是看错题了,以为只要上下对称就行了。正确的题意也很简单就是一个位置可以找到与他中心对称的三个位置,然后将数字依次填入的就好了。 有一个小陷阱,如果n是奇数可...

二营长的意大利炮友 192

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

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&...

侯山窝矿工 243

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

任意门: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 c...

Mod_13的博客 200

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

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. Fo...

weixin_42921101的博客 360

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

CodeForces - 1118C Palindromic Matrix (模拟,STL,排序)

????‍♀️ ????‍♀️ ????‍♀️ 重点在想清楚次数多的优先安排4,不会出现次数大的多次安排在2的地方。 //先把多的安排在需要四个的 //因为2是4的约数,不会出现次数大于等于四次还必须安排在2的情况 int num[MAXN]; int ans[22][22]; bool solve() { int n;cin>>n; vector<pii>v; rp...

欢迎光临 我的心 216

Palindromic Matrix CodeForces - 1118C (分块构造)

题目链接 题意:给定n ,给出n*n个[1,1000]的数 , 让你构造出一个中心对称矩阵,每个数用一次。 (1<=n<=20) 思路:先用优先队列,把数及其个数放进去维护。 由于矩阵中心对称, 如果是n是偶数的话,只需要填左上角那块就可以 ,其他的对应相等 。 如果n是奇数,左上角填完后需要把中间列 中间行补上去 。 填左上角的时候,每个数必须大于等于4个 填中间列、行的时候,每个数必须大于等于2个 #include<bits/stdc++.h> using namespace s

矮纸斜行闲作草 161

Educational Codeforces Round 89 (Rated for Div. 2) C. Palindromic Paths

C. Palindromic Paths time limit per test1.5 seconds memory limit per test256 megabytes inputstandard input outputstandard output You are given a matrix with n rows (numbered from 1 to n) and m columns (numbered from 1 to m). A number ai,j is written in the

张洪基 381

Palindromic Paths CodeForces - 1366C(思维+贪心)

You are given a matrix with n rows (numbered from 1 to n) and m columns (numbered from 1 to m). A number ai,j is written in the cell belonging to the i-th row and the j-th column, each number is either 0 or 1. A chip is initially in the cell (1,1), and it

starlet_kiss的博客 575

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
上一篇: CodeForces541div2-B-Draw!(有详细推导)
下一篇: Wrong Answer(构造法,智商被虐)- CodeForces div2 541
Mavis code
博客等级 码龄9年 13粉丝 147原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值