zoukankan      html  css  js  c++  java
  • 2015 NOIP day1 t1 神奇的幻方 模拟

    神奇的幻方

    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[200][200];
    int main()
    {
        scanf("%d",&n);
        x = 1,y = (n+1)/2;
        mp[x][y]=1;
        for(int i=2;i<=n*n;i++)
        {
            if(x==1&&y!=n)
                x=n,y++;
            else if(x!=1&&y==n)
                x--,y=1;
            else if(x==1&&y==n)
                x++;
            else if(!mp[x-1][y+1])
                x--,y++;
            else
                x++;
            mp[x][y]=i;
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
                printf("%d ",mp[i][j]);
            printf("
    ");
        }
    }
  • 相关阅读:
    企业级应用框架设计备忘录
    DBHelper
    Oracle客户端精简绿色版 不安装oracle客户端 转载
    回车转TAB
    excel列显示列号 转载
    XtraTreeList Drag Event
    XmlSerializer vs DataContractSerializer: Serialization in Wcf 转载
    转载 在Windows64位环境下.net访问Oracle解决方案
    正则表达式学习笔记
    SQL相关子查询的例子
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4948428.html
Copyright © 2011-2022 走看看