您的位置:首页 > 其它

2015 NOIP day1 t1 神奇的幻方 模拟

2015-11-08 21:39 344 查看

神奇的幻方

TimeLimit:20Sec

MemoryLimit:256MB

题目连接

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的幻方。

Undertwosituationstheplayercouldscoreonepoint.

⋅1.Ifyoutouchabuoybeforeyouropponent,youwillgetonepoint.Forexampleifyouropponenttouchthebuoy#2beforeyouafterstart,hewillscoreonepoint.Sowhenyoutouchthebuoy#2,youwon'tgetanypoint.Meanwhile,youcannottouchbuoy#3oranyotherbuoysbeforetouchingthebuoy#2.

⋅2.Ignoringthebuoysandrelyingondogfightingtogetpoint.
Ifyouandyouropponentmeetinthesameposition,youcantryto
fightwithyouropponenttoscoreonepoint.Fortheproposalofgame
balance,twoplayersarenotallowedtofightbeforebuoy#2istouchedbyanybody.

Therearethreetypesofplayers.

Speeder:
Asaplayerspecializinginhighspeedmovement,he/shetriestoavoid
dogfightingwhileattemptingtogainpointsbytouchingbuoys.
Fighter:
Asaplayerspecializingindogfighting,he/shealwaystriestofight
withtheopponenttoscorepoints.Sinceafighterisslowerthana
speeder,it'sdifficultforhim/hertoscorepointsbytouchingbuoys
whentheopponentisaspeeder.
All-Rounder:AbalancedplayerbetweenFighterandSpeeder.

TherewillbeatrainingmatchbetweenAsuka(All-Rounder)andShion(Speeder).
Sincethematchisonlyatrainingmatch,therulesaresimplified:thegamewillendafterthebuoy#1istouchedbyanybody.Shionisaspeedlover,andhisstrategyisverysimple:touchbuoy#2,#3,#4,#1alongtheshortestpath.

Asukaisgoodatdogfighting,soshewillalwaysscoreonepointbydogfightingwithShion,andtheopponentwillbestunnedforTsecondsafterdogfighting.
SinceAsukaisslowerthanShion,shedecidestofightwithShionfor
onlyonetimeduringthematch.ItisalsoassumedthatifAsukaand
Shiontouchthebuoyinthesametime,thepointwillbegiventoAsuka
andAsukacouldalsofightwithShionatthebuoy.Weassumethatin
suchscenario,thedogfightingmusthappenafterthebuoyistouchedby
AsukaorShion.

ThespeedofAsukaisV1m/s.ThespeedofShionisV2m/s.IsthereanypossibilityforAsukatowinthematch(tohavehigherscore)?

[b]Input[/b]

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

[b]Output[/b]

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

[b]SampleInput[/b]

3



[b]SampleOutput[/b]

816
357
492

HINT

[b]题意
[/b]

[b]题解:[/b]

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

[b]代码[/b]

#include<iostream>
#include<stdio.h>
#include<math.h>
usingnamespacestd;

intn,x,y;
intmp[200][200];
intmain()
{
scanf("%d",&n);
x=1,y=(n+1)/2;
mp[x][y]=1;
for(inti=2;i<=n*n;i++)
{
if(x==1&&y!=n)
x=n,y++;
elseif(x!=1&&y==n)
x--,y=1;
elseif(x==1&&y==n)
x++;
elseif(!mp[x-1][y+1])
x--,y++;
else
x++;
mp[x][y]=i;
}
for(inti=1;i<=n;i++)
{
for(intj=1;j<=n;j++)
printf("%d",mp[i][j]);
printf("\n");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: