NOIP 2015 神奇的幻方
模拟,注意为偶数的情况
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<malloc.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
const int N=;
#define LL long long
const double eps = 1e-;
const double pi = acos(-);
int g[][];
// inline int r(){
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
// return x*f;
// }
int n,x,y;
int mp[][];
int main()
{
scanf("%d",&n);
x = ,y = (n+)/;
mp[x][y]=;
for(int i=;i<=n*n;i++)
{
if(x==&&y!=n)
x=n,y++;
else if(x!=&&y==n)
x--,y=;
else if(x==&&y==n)
x++;
else if(!mp[x-][y+])
x--,y++;
else
x++;
mp[x][y]=i;
}
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++){
if(j==)
printf("%d",mp[i][j]);
else
printf(" %d",mp[i][j]);
}
printf("\n");
}
return ;
}
NOIP 2015 神奇的幻方的更多相关文章
- 【NOIP】提高组2015 神奇的幻方
[算法]模拟 #include<cstdio> ; int n,a[maxn][maxn]; int main() { scanf("%d",&n); ,y=n ...
- NOIP 2015
Prob.1 2015 神奇的幻方 模拟就好了.(这不是noip2017的初赛题么.)代码: #include<cstdio> #include<cstring> #inclu ...
- 2015 NOIP day1 t1 神奇的幻方 模拟
神奇的幻方 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.luogu.org/problem/show?pid=2615 Descri ...
- NOIp 2015真题模拟赛 By cellur925
果然我还是最菜的==不接受反驳== Day1 T1:神奇的幻方 思路:直接模拟即可,由于当前放法只与上一放法有关系,用两个变量记录一下即可.10分钟内切掉== 预计得分:100分 实际得分:100分 ...
- noip 2015 day1
T1 神奇的幻方 题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1 ...
- cogs 2109. [NOIP 2015] 运输计划 提高组Day2T3 树链剖分求LCA 二分答案 差分
2109. [NOIP 2015] 运输计划 ★★★☆ 输入文件:transport.in 输出文件:transport.out 简单对比时间限制:3 s 内存限制:256 MB [题 ...
- noip2015day1 T1 4510 神奇的幻方
4510 神奇的幻方 noip2015day1 T1 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Descripti ...
- NOIP 2015提高组复赛
神奇的幻方 题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1写在第 ...
- 4632 NOIP[2015] 运输计划
4632 NOIP[2015] 运输计划 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 大师 Master 题解 题目描述 Description 公元 2044 ...
随机推荐
- protobuf 向前兼容向后兼容
http://blog.163.com/jiang_tao_2010/blog/static/12112689020114305013458/ 不错的protobuf.. protobuf的编码方式: ...
- 【Unity3D】【NGUI】本地生成API文档
原地址:http://blog.csdn.net/u012091672/article/details/17438135 NGUI讨论群:333417608 1.安装Doxygen(http://ww ...
- 【leetcode】3Sum Closest(middle)
Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...
- ***CI异常记录到日志:CodeIgniter中设计一个全局exception hook
在CodeIgniter中,当发生异常时,经常要通知系统管理员,因此有必要在全局的高度上 捕捉异常,因此可以写一个hook, 比如在config目录的hook.php中,加入: $hook['pre_ ...
- 将ANGULAR与后端请求结合
简单的结合,却是很多应用的基础.RESTFUL就此而生.瘦服务,富客户. <!DOCTYPE html> <html lang="en" ng-app=" ...
- hadoop No FileSystem for scheme: hdfs
http://stackoverflow.com/questions/17265002/hadoop-no-filesystem-for-scheme-file This is a typical c ...
- Pig安装及简单使用(pig版本0.13.0,Hadoop版本2.5.0)
原文地址:http://www.linuxidc.com/Linux/2014-03/99055.htm 我们用MapReduce进行数据分析.当业务比较复杂的时候,使用MapReduce将会是一个很 ...
- UIActinSheet和UIActionSheetDelegate
UIActinSheet和UIActionSheetDelegate 这个是就那个UIActionSheet对象 一般用来选择类型或者改变界面...还有更多应用 定义如下:UIActionSheet ...
- 关于Apache Struts 2 S2-032高危漏洞的一些确认
2016年4月21日Struts2官方发布两个CVE,其中CVE-2016-3081(S2-032)官方评级为高. 主要原因为在用户开启动态方法调用的情况下,会被攻击者实现远程代码执行攻击. 具体的漏 ...
- Linux C/C++ 编程练手 --- 大数相加和大数相乘
最近写了一个大数相乘和相加的程序,结果看起来是对的.不过期间的效率可能不是最好的,有些地方也是临时为了解决问题而直接写出来的. 可以大概说一下相乘和相加的解决思路(当然,大数操作基本就是两个字符串的操 ...