链接: https://pan.baidu.com/s/1vA0figJjqOfO0-edUO7TNQ
提取码: cta4
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
// 蚂蚁迷宫问题
static void Main(string[] args)
{
// 1,0 = 4 // 偶数的平方
// 0,2 = 9 // 奇数的平方
// 3,0 = 16 // 偶数的平方
// 0,4 = 25 // 奇数的平方
String str;
while ((str = Console.ReadLine()) != null)
{
/////////////////////////////////////////////////////////
// 对数字进行开方,算到平方数
Double n = Math.Sqrt(Int64.Parse(str.Replace("_", "")));
String s = Convert.ToString(n);
if (s.Contains("."))
{
Int64 src = Int64.Parse(str.Replace("_", ""));
Int64 from = Convert.ToInt64(Math.Floor(n));
// 如果区间是 偶(n)->奇(n+1) 见表得 ->1位 ↑n位 <-n位
if (from % 2 == 0)
{
// 坐标定 (n-1,0)
Int64 position = from * from;
// 剩余多少位
Int64 left = src - position;
if (left == 1)
{
Console.WriteLine("0 {0}", from);
}
else if (left <= from + 1)
{
Int64 y = left - 1;
Console.WriteLine("{0} {1}", y, from);
}
else
{
Int64 y = (from + 1) * (from + 1) - src;
Console.WriteLine("{0} {1}", from, y);
}
}
// 如果区间是 奇(n)->偶(n+1) 见表得 ↑1位 ->n位 ↓n位
if (from % 2 == 1)
{
// 坐标定 (n-1,0)
Int64 position = from * from;
// 剩余多少位
Int64 left = src - position;
if (left == 1)
{
Console.WriteLine("{0} 0", from);
}
else if (left <= from + 1)
{
Int64 y = left - 1;
Console.WriteLine("{0} {1}", from, y);
}
else
{
Int64 y = (from + 1) * (from + 1) - src;
Console.WriteLine("{0} {1}", y, from);
}
}
}
else
{
Int64 from = Convert.ToInt64(Math.Floor(n));
if (from % 2 == 0)
{
Console.WriteLine("0 {0}", from - 1);
}
else
{
Console.WriteLine("{0} 0", from - 1);
}
}
}
}
}
}