神奇的幻方

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://www.luogu.org/problem/show?pid=2615

Description

幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行、每列及两条对角线上的数字之和都相同。
  当N为奇数时,我们可以通过以下方法构建一个幻方:
  首先将1写在第一行的中间。
  之后,按如下方式从小到大依次填写每个数K(K=2,3,…,N*N):
  1.若(K−1)在第一行但不在最后一列,则将K填在最后一行,(K−1)所在列的右一列;
  2.若(K−1)在最后一列但不在第一行,则将K填在第一列,(K−1)所在行的上一行;
  3.若(K−1)在第一行最后一列,则将K填在(K−1)的正下方;
  4.若(K−1)既不在第一行,也不在最后一列,如果(K−1)的右上方还未填数,则将K填在(K−1)的右上方,否则将K填在(K−1)的正下方。
  现给定N请按上述方法构造N*N的幻方。
Under two situations the player could score one point.

⋅1. If you touch a buoy before your opponent, you will get one point. For example if your opponent touch the buoy #2 before you after start, he will score one point. So when you touch the buoy #2, you won't get any point. Meanwhile, you cannot touch buoy #3 or any other buoys before touching the buoy #2.

⋅2. Ignoring the buoys and relying on dogfighting to get point.
If you and your opponent meet in the same position, you can try to
fight with your opponent to score one point. For the proposal of game
balance, two players are not allowed to fight before buoy #2 is touched by anybody.

There are three types of players.

Speeder:
As a player specializing in high speed movement, he/she tries to avoid
dogfighting while attempting to gain points by touching buoys.
Fighter:
As a player specializing in dogfighting, he/she always tries to fight
with the opponent to score points. Since a fighter is slower than a
speeder, it's difficult for him/her to score points by touching buoys
when the opponent is a speeder.
All-Rounder: A balanced player between Fighter and Speeder.

There will be a training match between Asuka (All-Rounder) and Shion (Speeder).
Since the match is only a training match, the rules are simplified: the game will end after the buoy #1 is touched by anybody. Shion is a speed lover, and his strategy is very simple: touch buoy #2,#3,#4,#1 along the shortest path.

Asuka is good at dogfighting, so she will always score one point by dogfighting with Shion, and the opponent will be stunned for T seconds after dogfighting.
Since Asuka is slower than Shion, she decides to fight with Shion for
only one time during the match. It is also assumed that if Asuka and
Shion touch the buoy in the same time, the point will be given to Asuka
and Asuka could also fight with Shion at the buoy. We assume that in
such scenario, the dogfighting must happen after the buoy is touched by
Asuka or Shion.

The speed of Asuka is V1 m/s. The speed of Shion is V2 m/s. Is there any possibility for Asuka to win the match (to have higher score)?

Input

输入文件只有一行,包含一个整数N即幻方的大小。

Output

输出文件包含N行,每行N个整数,即按上述方法构造出的N*N的幻方。相邻两个整数之间用单个空格隔开。

Sample Input

3
 

Sample Output

8 1 6
3 5 7
4 9 2

HINT

题意

题解:

模拟题模拟题,热情的100分

代码

#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std; 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++)
printf("%d ",mp[i][j]);
printf("\n");
}
}

2015 NOIP day1 t1 神奇的幻方 模拟的更多相关文章

  1. 【NOIP2015提高组】Day1 t1神奇的幻方

    一大淼题,直接瞎搞即可,不过一定要仔细看题目给定的条件. #include<iostream> #include<cstdio> #include<cstring> ...

  2. 东方14模拟赛之noip2015/day1/3/神奇的幻方

    总时间限制:  10000ms 单个测试点时间限制:  1000ms 内存限制:  128000kB 描述 幻方是一种很神奇的N*N 矩阵:它由数字 1,2,3, … …,N*N 构成,且每行.每列及 ...

  3. 洛谷 P2615 神奇的幻方 —— 模拟

    题目:https://www.luogu.org/problemnew/show/P2615 直接按题意模拟即可; 用 Emacs 做的第一道题! 代码如下: #include<iostream ...

  4. noip2015day1 T1 4510 神奇的幻方

    4510 神奇的幻方 noip2015day1 T1  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Descripti ...

  5. 2015 Noip提高组 Day1

    P2615 神奇的幻方 [题目描述] 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: ...

  6. [模拟][NOIP2015]神奇的幻方

    神奇的幻方 题目描述 幻方是一种很神奇的N∗ N矩阵:它由数字 1,2,3, … … , N ∗ N 构成,且每行.每列及两条对角线上的数字之和都相同. 当 N为奇数时,我们可以通过以下方法构建一个幻 ...

  7. P2615 神奇的幻方

    P2615 神奇的幻方 题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首 ...

  8. 洛谷 P2615 神奇的幻方

    传送门 I'm here! 思路 这个题,我们可以直接去模拟,因为范围很小,且\(N\)都是奇数 直接构造一个矩阵,初始值都为\(0\),然后\(while\)循环,根据题目给出的\(4\)个条件进行 ...

  9. Noip2011 提高组 Day1 T1 铺地毯 + Day2 T1 计算系数

    Day1 T1 题目描述 为了准备一个独特的颁奖典礼,组织者在会场的一片矩形区域(可看做是平面直角坐标系的第一象限)铺上一些矩形地毯.一共有 n 张地毯,编号从 1 到n .现在将这些地毯按照编号从小 ...

随机推荐

  1. liunx环境下的mysql数据库配置文件my.conf内的参数含义

    [client]port = 3306socket = /tmp/mysql.sock [mysqld]port = 3306socket = /tmp/mysql.sock basedir = /u ...

  2. 【转】APUE习题4.6---测试lseek作用

    原文网址:http://m.blog.csdn.net/blog/u014488381/42556509 原题:如果使用追加标志打开一个文件以便读.写,能否仍用 lseek 在任一为止开始读?能否用 ...

  3. GitHub开源库排名一百的简单介绍,值得收藏!

    GitHub Android Libraries Top 100 简介 本项目主要对目前 GitHub 上排名前 100 的 Android 开源库进行简单的介绍, 至于排名完全是根据 GitHub ...

  4. iOS AFNetworking的使用

    转:http://www.cnblogs.com/lookenwu/p/3927897.html AFNetworking几乎是iOS上最常用的HTTP库了,AFNetworking也确实用起来简单, ...

  5. HDU 5387 Clock

    题意:给一个时间,求三个时针之间的夹角,分数表示. 解法:算算算.统一了一下分母. 代码: #include<stdio.h> #include<iostream> #incl ...

  6. div模拟的下拉框特效jquery

    从网上找来的,感觉不错就拿来分享下 <style type="text/css"> body, ul, li { margin: 0; padding: 0; font ...

  7. 常用SQL语句汇总整理

    1.SQL 插入语句得到自动生成的递增ID 值 insert into Table1(Name,des,num) values (''ltp'',''thisisbest'',10); select ...

  8. 10款jquery图片广告特效的预览及源码下载 改自[帅的相对论]

    原文格式有问题,我来排版了一下,分享给大家. 1.jQuery仿海尔官网全屏焦点图特效代码 Query仿海尔官网全屏焦点图特效代码,带有左右箭头的jQuery焦点图切换特效.当焦点图切换时,下方的三块 ...

  9. 看仪表盘——validation

    先试想一下,对于一个简单的二分类问题,我们如何选择合适的算法? 我们有许许多多的H,如何选择出最为合适的算法? 最合理的方法是:对于每一个H,我们选择出Eout最小的g,然后对于各个g,再选择Eout ...

  10. 纯CSS3实现宽屏二级下拉菜单

    今天我们要来分享一款基于纯CSS3的宽屏二级下拉菜单,这款菜单的子菜单在展开的时候是很宽敞的,菜单项中可以自定义格式的内容,非常实用,也很大气.由于是用纯CSS3实现,所以这款下拉菜单不用运行Java ...