2015 NOIP day1 t1 神奇的幻方 模拟
2015-11-08 21:39
344 查看
神奇的幻方
TimeLimit:20SecMemoryLimit:256MB
题目连接
http://www.luogu.org/problem/show?pid=2615Description
幻方是一种很神奇的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");
}
}
相关文章推荐
- K-means算法
- 5233杨光--第十章
- 设计模式 --> (8)组合模式
- c++面试常用知识(sizeof计算类的大小,虚拟继承,重载,隐藏,覆盖)
- android获取string.xml的值
- Python爬虫入门
- 编程之美-双线程高效下载方法整理
- Java基础知识
- HTTP集群之nginx+keepalived
- Struts2+CKEditor实现web编辑器
- Java----再学习-----Java多态、继承、接口
- JVM系列五:JVM监测&工具[整理中]
- C++11新特性之 std::array container
- C++11新特性之 std::array container
- Android网络编程简介
- NSNotificationCenter用法总结
- iOS 状态栏管理
- 如何准备性能测试数据
- The Antivirus Hacker's Handbook 读书笔记
- LintCode-矩阵的之字型遍历