zoukankan      html  css  js  c++  java
  • NOIP 2015 神奇的幻方

    模拟,注意为偶数的情况

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<cstdlib>
     4 #include<iostream>
     5 #include<queue>
     6 #include<stack>
     7 #include<cmath>
     8 #include<algorithm>
     9 #include<malloc.h>
    10 using namespace std;
    11 #define clc(a,b) memset(a,b,sizeof(a))
    12 #define inf 0x3f3f3f3f
    13 const int N=10010;
    14 #define LL long long
    15 const double eps = 1e-5;
    16 const double pi = acos(-1);
    17  int g[1010][1010];
    18 // inline int r(){
    19 //     int x=0,f=1;char ch=getchar();
    20 //     while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
    21 //     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    22 //     return x*f;
    23 // }
    24 int n,x,y;
    25 int mp[200][200];
    26 int main()
    27 {
    28     scanf("%d",&n);
    29     x = 1,y = (n+1)/2;
    30     mp[x][y]=1;
    31     for(int i=2;i<=n*n;i++)
    32     {
    33         if(x==1&&y!=n)
    34             x=n,y++;
    35         else if(x!=1&&y==n)
    36             x--,y=1;
    37         else if(x==1&&y==n)
    38             x++;
    39         else if(!mp[x-1][y+1])
    40             x--,y++;
    41         else
    42             x++;
    43         mp[x][y]=i;
    44     }
    45     for(int i=1;i<=n;i++)
    46     {
    47         for(int j=1;j<=n;j++){
    48             if(j==1)
    49             printf("%d",mp[i][j]);
    50         else
    51             printf(" %d",mp[i][j]);
    52         }
    53         printf("
    ");
    54     }
    55     return 0;
    56 }
    View Code
  • 相关阅读:
    .net ORM架构列表
    C#向win32程序窗口中的文本框设置指定文本
    C#串口通信总结
    MPF配置文件参数管理
    WF牛人们的资源
    BDD初步
    DevExpress 汉化(简单、实用、快速)
    WPF中的命令简述(Command)
    Devexpress汉化资源
    Silverlight架构列表
  • 原文地址:https://www.cnblogs.com/ITUPC/p/5425980.html
Copyright © 2011-2022 走看看