結果
問題 | No.401 数字の渦巻き |
ユーザー |
![]() |
提出日時 | 2016-07-23 18:00:37 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 24 ms / 2,000 ms |
コード長 | 2,540 bytes |
コンパイル時間 | 3,020 ms |
コンパイル使用メモリ | 106,496 KB |
実行使用メモリ | 17,792 KB |
最終ジャッジ日時 | 2024-11-06 15:05:43 |
合計ジャッジ時間 | 4,871 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;using System.Collections.Generic;//No401 数字の渦巻きclass Program{static string InputPattern = "InputX";static List<string> GetInputList(){var WillReturn = new List<string>();if (InputPattern == "Input1") {WillReturn.Add("3");//001 002 003//008 009 004//007 006 005}else if (InputPattern == "Input2") {WillReturn.Add("4");//001 002 003 004//012 013 014 005//011 016 015 006//010 009 008 007}else {string wkStr;while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);}return WillReturn;}static void Main(){List<string> InputList = GetInputList();int N = int.Parse(InputList[0]);int UB = N - 1;int[,] BanArr = new int[UB + 1, UB + 1];int CurrX = 0, CurrY = 0;int VisitedCnt = 0;//0が右向き//1が下向き//2が左向き//3が上向きint Muki = 0;while (true) {BanArr[CurrX, CurrY] = ++VisitedCnt;if (VisitedCnt == (UB + 1) * (UB + 1)) break;//次のマスに進むwhile (true) {int HeniX, HeniY;DeriveHeni(Muki, out HeniX, out HeniY);int NewX = CurrX + HeniX;int NewY = CurrY + HeniY;if (NewX < 0 || UB < NewX|| NewY < 0 || UB < NewY|| BanArr[NewX, NewY] != 0) {Muki = (Muki + 1) % 4;continue;}CurrX = NewX; CurrY = NewY;break;}}var sb = new System.Text.StringBuilder();for (int Y = 0; Y <= UB; Y++) {for (int X = 0; X <= UB; X++) {if (X > 0) sb.Append(' ');sb.Append(BanArr[X, Y].ToString().PadLeft(3, '0'));}sb.AppendLine();}Console.Write(sb.ToString());}//向きを引数として、変位をセットstatic void DeriveHeni(int pMuki, out int pHeniX, out int pHeniY){pHeniX = pHeniY = -1;if (pMuki == 0) { pHeniX = 1; pHeniY = 0; };if (pMuki == 1) { pHeniX = 0; pHeniY = -1; };if (pMuki == 2) { pHeniX = -1; pHeniY = 0; };if (pMuki == 3) { pHeniX = 0; pHeniY = 1; };}}