【ACM】蛇形填数 - 逻辑怪
蛇形填数
- 描述
- 在n*n方陈里填入1,2,...,n*n,要求填成蛇形。例如n=4时方陈为:
10 11 12 1
9 16 13 2
8 15 14 3
7 6 5 4
- 输入
- 直接输入方陈的维数,即n的值。(n<=100)
- 输出
- 输出结果是蛇形方陈。
- 样例输入
-
3
- 样例输出
-
7 8 1
6 9 2
5 4 3
#include <iostream>
#include <cmath>
#include <cstdio> using namespace std; int main(){ int n;
cin>>n;
int **a = new int *[n];
for (int i = ; i < n ; i++)
{
a[i] = new int[n];
}
int sum = ;
int x = , y = n-;
int circle = ;
while (sum<n*n)
{
while (x<n-circle) //down
{
a[x][y] = sum++;
x++;
}
while (y>circle-)
{
a[x][y] = sum++;
y--;
}
while (x>circle-)
{
a[x][y] = sum++;
x--;
}
while (y<n-circle)
{
a[x][y] = sum++;
y++;
}
x++;y--;
circle++;
}
if (n%!=)
{
a[x][y] = n*n;
}
int i,j;
for (i = ; i < n ; i++)
{
for (j = ; j < n-; j++)
{
cout<<a[i][j]<<" ";
}
cout<<a[i][j]<<endl;
} return ;
}
【ACM】蛇形填数 - 逻辑怪的更多相关文章
- ACM 蛇形填数
蛇形填数 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 在n*n方陈里填入1,2,...,n*n,要求填成蛇形.例如n=4时方陈为:10 11 12 19 16 1 ...
- nyoj 33 蛇形填数
蛇形填数 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 在n*n方陈里填入1,2,...,n*n,要求填成蛇形.例如n=4时方陈为: 10 11 ...
- <蛇形填数>--算法竞赛 入门经典(第2版)- 3.1 数组 程序3-3 蛇形填数
蛇形填数: 在n×n方阵里填入1,2,....,n×n,要求填成蛇形.例如,n = 4 时方阵为: 10 11 12 1 9 16 13 2 8 15 14 3 7 ...
- ny33 蛇形填数
蛇形填数 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 在n*n方陈里填入1,2,...,n*n,要求填成蛇形.例如n=4时方陈为: 10 11 12 1 9 16 1 ...
- 梦工厂实验室 蛇形填数 dfs
问题 D: 蛇形填数 时间限制: 3 Sec 内存限制: 64 MB提交: 28 解决: 5[提交][状态][讨论版] 题目描述 在n*n方阵里填入1,2,...,n*n,要求填成蛇形.例如n=4 ...
- nyoj_33_蛇形填数_201308221636
蛇形填数时间限制:3000 ms | 内存限制:65535 KB 难度:3描述 在n*n方陈里填入1,2,...,n*n,要求填成蛇形.例如n=4时方陈为:10 11 12 19 16 13 28 ...
- nyoj33 蛇形填数
蛇形填数 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描写叙述 在n*n方陈里填入1,2,...,n*n,要求填成蛇形.比如n=4时方陈为: 10 11 12 1 9 16 ...
- [C++]蛇形填数
[从左下角开始,逆时针蛇形填数] #include <iostream> using namespace std; int main() { int n; cin>>n; in ...
- 蛇形填数(JAVA语言)
package 第三章; import java.util.Scanner; public class 蛇形填数 { public static void main(String[] args) { ...
随机推荐
- 获取当前设备的CPU个数
public class Test { public static void main(String[] args) { //获取当前设备的CPU个数 int availableProcessors ...
- Entity Framework Tutorial Basics(29):Stored Procedure in Entity Framework
Stored Procedure in Entity Framework: Entity Framework has the ability to automatically build native ...
- Entity Framework Tutorial Basics(23):Add Single Entity
Add New Entity using DBContext in Disconnected Scenario: In this chapter you will learn how to add n ...
- netty源码阅读之UnpooledByteBufAllocator
使用IDEA阅读源码Navigate下面的工具是个好东西 .可以帮助分析类的结构等 ByteBufAllocator主要用来生成三种ByteBuf :HeadBuffer,DirectBuffer,C ...
- C#实现远程开机(局域网测试通过)
首先介绍相关知识. UDP协议 UDP 是User Datagram Protocol的简称, 中文名是用户数据报协议,是OSI(Open System Interconnection,开放式系统互联 ...
- sqlserver 时间差转换为天时分秒
DECLARE @starttime DATETIME = '2016-12-01' , @endtime DATETIME = '2016-12-02 14:56:39.927'; DECLARE ...
- iOS状态栏、导航栏的设置
简单的参考 1.状态栏(statusBar) 默认:黑色 改变为白色: 1.1 第一步: info.plist中添加View controller-based status bar appearanc ...
- 787. Cheapest Flights Within K Stops
There are n cities connected by m flights. Each fight starts from city u and arrives at v with a pri ...
- uoj#453. 【集训队作业2018】围绕着我们的圆环(线性代数+递推)
题面 传送门 题解 我对线代一无所知 如果下面有啥说错的地方请说出来省的我一辈子都搞不明白 如果你没看懂以下在讲什么不要紧,因为我也没看懂 首先,关于\(A\times B \equiv C \pmo ...
- 51nod1244 莫比乌斯函数之和(杜教筛)
题面 传送门 题解 我--我忘记把预处理的块的大小调成\(n^{\frac{2}{3}}\)了--(仰天) 首先\(\mu*1=e\) 然后杜教筛就行了 //minamoto #include< ...