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 <vector>
#include <algorithm> using namespace std; const int dx[] = {, , -, };
const int dy[] = {, -, , }; int main(){
int n;
cin >> n;
vector<vector<int> > matrix(n+,vector<int>(n+,));
for (int i = ; i < n+; ++ i) {
matrix[][i] = matrix[n+][i] = ;
matrix[i][] = matrix[i][n+] = ;
}
int step = , x = , y = n, cnt = ;
while(cnt !=n*n){
step %=;
while(matrix[x+dx[step]][y+dy[step]] == ){
x +=dx[step];
y +=dy[step];
matrix[x][y] = ++cnt;
}
step++;
} for (int i = ; i <= n; ++ i) {
cout<<matrix[i][];
for(int j = ; j <=n; ++ j)
cout<<" "<<matrix[i][j];
cout<<endl;
}
}
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) { ...
随机推荐
- sshd_conf AllowUsers参数
AllowUsers root user1 user2 #服务器只允许root user1 user2登录,再的新也用户产生,是不允许豋录服务器 配置文件在/etc/ssh/sshd_confing ...
- python 取两数的百分比
Python (r266:, Jan , ::) [GCC (Red Hat -)] on linux2 Type "help", "copyright", & ...
- Sexagenary Cycle(天干地支法表示农历年份)
Sexagenary Cycle Time Limit: 2 Seconds Memory Limit: 65536 KB 题目链接:zoj 4669 The Chinese sexagen ...
- 自制工具:迅速打开一个Node 环境的Playground
需求 经常有这种情况,写代码的时候需要实验种想法,亟需一种playground 环境来玩耍.如果是前端的话可以打开chrome 的控制台,但是如果是Node 的话就比较麻烦了.我要打开我的存放试验代码 ...
- wp8 入门到精通 定时更新瓷贴
public class ScheduledAgent : ScheduledTaskAgent { static ScheduledAgent() { Deployment.Current.Disp ...
- C# Func<T,TResult>
using System; namespace FuncDemo { internal class Program { private static void Main() { //类似委托功能 Fu ...
- VMWARE虚拟机CentOS6.4系统使用主机无线网卡上网的三种方法介绍
转自:http://www.jb51.net/network/98820.html 如何真正的实现VMWARE虚拟机CentOS6.4系统使用主机无线网卡上网 环境:WIN7旗舰版,台式机,U盘无 ...
- JDK中的设计模式
Creational(创建模式) Abstract factory: 创建一组有关联的对象实例.这个模式在JDK中也是相当的常见,还有很多的framework例如Spring.我们很容易找到这样的实例 ...
- 细说static关键字及其应用
场景 先看段代码,考虑以下场景,其运行结果是什么? public class Test { static int i = 8; public void printI() { int i = 88; S ...
- html css js 一些记录.
webstorm 的基本使用 webstorm 格式化 html 代码: Ctrl+Alt+L js html css 基本使用 注意 dom 的 innerHTML会刷新dom,所以里面包含的事件绑 ...