codeforces 710C
1 second
256 megabytes
standard input
standard output
Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd.
The only line contains odd integer n (1 ≤ n ≤ 49).
Print n lines with n integers. All the integers should be different and from 1 to n2. The sum in each row, column and both main diagonals should be odd.
1
1
3
2 1 43 5 76 9 8
题义就是N*N的方格里面填数1~N*N,横列斜和为奇数
哎,艰辛啊。。。
#include <bits/stdc++.h> using namespace std; #define Maxn 55 int MAP[Maxn][Maxn]; bool visit[Maxn][Maxn]; int main(){ int N; cin >> N; memset(visit,false,sizeof(visit)); for(int i = 1; i <= N; i++){ for(int j = 1; j <= N; j++){ if( i >= (j- N/2) && i <= (j + N/2) && i + j >= ((N+3)/2) && i + j <= (N+(N+1)/2) ){ visit[i][j] = true; }else{ visit[i][j] = false; } } } int jishu = 1; int oushu = 2; for(int i = 1; i <= N; i++){ for(int j = 1; j <= N; j++){ if(visit[i][j]){ cout << jishu << " "; jishu += 2; }else{ cout << oushu << " "; oushu += 2; } } cout << endl; } }
codeforces 710C的更多相关文章
- 【模拟】Codeforces 710C Magic Odd Square
题目链接: http://codeforces.com/problemset/problem/710/C 题目大意: 构造一个N*N的幻方.任意可行解. 幻方就是每一行,每一列,两条对角线的和都相等. ...
- Codeforces 710C. Magic Odd Square n阶幻方
C. Magic Odd Square time limit per test:1 second memory limit per test:256 megabytes input:standard ...
- CodeForces 710C Magic Odd Square (n阶奇幻方)
题意:给它定一个n,让你输出一个n*n的矩阵,使得整个矩阵,每行,每列,对角线和都是奇数. 析:这个题可以用n阶奇幻方来解决,当然也可以不用,如果不懂,请看:http://www.cnblogs.co ...
- CodeForces 710C Magic Odd Square
构造. 先只考虑用$0$和$1$构造矩阵. $n=1$,$\left[ 1 \right]$. $n=3$,(在$n=1$的基础上,最外一圈依次标上$0$,$1$,$0$,$1$......) $\l ...
- CodeForces - 710C Magic Odd Square(奇数和幻方构造)
Magic Odd Square Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, c ...
- codeforces 710C C. Magic Odd Square(构造)
题目链接: C. Magic Odd Square Find an n × n matrix with different numbers from 1 to n2, so the sum in ea ...
- codeforces 710C Magic Odd Square(构造或者n阶幻方)
Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both ma ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
随机推荐
- 关于项目既要使用ant脚本又要使用maven pom.xml文件的问题
背景:项目使用的是ant脚本打包,但又需要maven去执行sonar代码扫描.所以项目中既有build.xml又有pom.xml build.xml设置的打包后产物文件夹为target,maven运行 ...
- HDU1878欧拉回路
这道题WA了好多次.测试数据感觉有点问题-- 并查集啊,必须有. #include<stdio.h> #include<string.h> int ad[1003]; int ...
- SlidesJS 3.0.4 在手机上遇到的一些问题及解决办法
SlidesJS 3.0.4 http://slidesjs.com 在手机上遇到的一些问题及解决办法 1.手机上打开有sliderjs的页面后, 切换到别的页面再回来时, sliderjs部分不能滑 ...
- 能用存储过程的DBHelper类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- WPF学习(二)布局与菜单、工具栏
布局 //表格①Grid//3列 4行的表格 <Grid> <Grid.ColumDefinitions> <ColumnDefinti ...
- [转] CSS direction属性简介与实际应用 ---张鑫旭
一.用的少并不代表没有用 至少,在我接触的这么多项目里,没有见到使用过CSS direction属性做实际开发的. 为什么呢?是因为direction长得丑吗? 虽然说direction确实其貌不扬, ...
- window scipy install
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy whl包,使用pip install xx.whl 安装 1:先安装 numpy+mkl. whl ...
- python随机数
前提:需要导入random模块 >>>import random 1.random.random random.random()用于生成一个0到1的随机符小数: 0 <= n ...
- Table view 备忘
Table view 备忘 本篇会以备忘为主,主要是一些基础的代理方法和数据源方法具体的优化好点子会后续跟上. Table view的数据源方法 必须实现的数据源方法 // 返回每一行的cell,可以 ...
- Quartz1.8.5例子(五)
/* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...