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 ...
随机推荐
- 函数还能这样玩儿~实现类似add(1)(2)(3)的函数
人生的第一份前端工作找到了,感谢大神主子们给半路出家自学的我这么多的机会,很高兴正式踏上客观又乐趣满满的程序员之路,哇咔咔咔. 分享一个准备面试时遇到的一个有趣的问题: 要求实现类似add(1)( ...
- 常用css表达式-最小宽度-上下居中
/* IE6下最小宽度的CSS表达式 */ width:100%; min-width:1024px; _width:expression((document.documentElement.clie ...
- session与cookie的区别,有哪些不同之处
session与cookie的区别,根据自己的理解总结如下: (1)cookie是一种客户端的状态管理技术,将状态写在 浏览器端,而session是一种服务器端的状态管理技术,将 状态写在web服务器 ...
- 移动端触摸滑动插件Swiper
移动端触摸滑动插件Swiper 04/02/2015 一.了解Swiper 目前移动端项目一般都需要具有触屏焦点图的效果,如果你也需要实现这一功能的话,Swiper是一个不错的选择. 1.他不需要加载 ...
- WPF之 XAML集合项简单演示
我们直接通过xaml文件演示一个简单的xaml集合项: <Window x:Class="WPF_XAML集合项.MainWindow" xmlns="http:/ ...
- Elasticsearch客户端大全 http://www.searchtech.pro/elasticsearch-clients
Elasticsearch有各种语言的客户端,下面一一列出来: Perl ElasticSearch.pm: Perl客户端 Python pyes: Python客户端pyelasticsearch ...
- HTML+JS版本的俄罗斯方块
<!doctype html><html><head></head><body> <div id="box" st ...
- golang-mongodb范例
package main import ( "log" "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" ) ...
- js performance
http://hqman.me/2012/js-module.html http://www.cnblogs.com/snandy/archive/2012/06/06/2536969.html ht ...
- 在Eclipse中安装spket插件
spket是一个开发JavaScript和Ext等的开发工具,它可以 是独立的IDE,也可以作为 Eclipse的插件使用,下面介绍如何在Eclipse中安装spket插件, 1.首先上 官网 htt ...