Codeforces 710 C. Magic Odd Square(构造)——Educational Codeforces Round 16
来源:互联网 发布:飞思卡尔单片机与pic 编辑:程序博客网 时间:2024/05/29 16:05
传送门
Find an
Input
The only line contains odd integer
Output
Print
Examples
input
1
output
1
input
3
output
2 1 43 5 76 9 8
题目大意:
给你一个数
成的,构成的这个矩阵需要满足一个条件:
每一行 每一列 以及主对角线上的元素和必须是奇数。
让你输出这个矩阵,(输入数据保证
解题思路:
举一些例子:(其中
当
矩阵是:
当
矩阵是:
当
矩阵式:
通过这些例子我们可以发现一些规律,就是按照对称的摆这些奇数就行了,找出这个规
律来了就行了。
/**2016 - 08 - 24 下午Author: ITAKMotto:今日的我要超越昨日的我,明日的我要胜过今日的我,以创作出更好的代码为目标,不断地超越自己。**/#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include <algorithm>#include <set>using namespace std;typedef long long LL;typedef unsigned long long ULL;const int INF = 1e9+5;const int MAXN = 1e2+5;const int MOD = 1e9+7;const double eps = 1e-7;const double PI = acos(-1);using namespace std;LL Scan_LL()///输入外挂{ LL res=0,ch,flag=0; if((ch=getchar())=='-') flag=1; else if(ch>='0'&&ch<='9') res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0'; return flag?-res:res;}int Scan_Int()///输入外挂{ int res=0,ch,flag=0; if((ch=getchar())=='-') flag=1; else if(ch>='0'&&ch<='9') res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0'; return flag?-res:res;}void Out(LL a)///输出外挂{ if(a>9) Out(a/10); putchar(a%10+'0');}int a[MAXN][MAXN];void Init(int n){ memset(a, 0, sizeof(a)); for(int i=1; i<=n/2+1; i++) for(int j=n/2+2-i; j<=n/2+i; j++) a[i][j] = a[n-i+1][j] = 1;}int main(){ int n; while(~scanf("%d",&n)) { Init(n); int tp1 = 1, tp2 = 2; for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { if(a[i][j]) { cout<<tp1<<" "; tp1 += 2; } else { cout<<tp2<<" "; tp2 += 2; } } cout<<endl; } } return 0;}
0 0
- Codeforces 710 C. Magic Odd Square(构造)——Educational Codeforces Round 16
- Educational Codeforces Round 16 C. Magic Odd Square (构造)
- 【Educational Codeforces Round 16】Codeforces 710C Magic Odd Square
- Educational Codeforces Round 16 Magic Odd Square
- Educational Codeforces Round 16 C. Magic Odd Square
- Educational Codeforces Round 16 C. Magic Odd Square
- Educational Codeforces Round 16 C. Magic Odd Square
- Educational Codeforces Round 16 C 题 Magic Odd Square
- Educational Codeforces Round 16 C. Magic Odd Square
- Educational Codeforces Round 16-C. Magic Odd Square
- Educational Codeforces Round 16 -- C - Magic Odd Square (找规律)
- codeforces 710 C. Magic Odd Square(构造)
- CodeForces-710C Magic Odd Square(幻方问题/构造)
- codeforces 710C C. Magic Odd Square
- codeforces 710C Magic Odd Square
- 【模拟】Codeforces 710C Magic Odd Square
- Codeforces 710C-Magic Odd Square
- Codeforces Problem 710C Magic Odd Square
- Keepalived虚拟机搭建(适用于真实服务器)
- openstack_ice之wsgi详解(paste从ini配置文件->routesr具体发布流程)
- Linux中chown和chmod使用注意及区别
- CentOS6.5系统安装及LAMP环境安装(yum方式)配置详解(四)
- Jackson 框架,轻易转换JSON
- Codeforces 710 C. Magic Odd Square(构造)——Educational Codeforces Round 16
- c# 连接sqlserver
- HTML基础知识整理
- UVA 11401
- spring学习总结(二)
- Spring MVC @SessionAttributes注解
- CNTK学习笔记 -- Computation Network part 1 -- Forward and Backward Algorithm
- EasyUI学习第四篇:Layout布局
- window 下 nginx php 环境搭建