[ACM]Q10233: Dermuba Triangle
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
namespace Q10233
{
class Program
{
static private BigInteger[] bi; static private char[] par = { ' ' }; static private Point p1, p2;
static void Main(string[] args)
{
for (; ; )
{
labelnm: Console.Write("n m>>>");
try
{
bi = Array.ConvertAll<string, BigInteger>(Console.ReadLine().Split(par, StringSplitOptions.RemoveEmptyEntries), BigInteger.Parse);
if (bi.Length != 2) throw new Exception();
}
catch { goto labelnm; }
bi[0]++; bi[1]++;
p1 = new Point(); p2 = new Point();
p1.X = (int)Math.Ceiling(Math.Sqrt((double)bi[0])) - 1;
p1.Y = (bi[0] - p1.X * p1.X) % 2 == 0 ? 2 + 3 * p1.X - 1 : 2 + 3 * p1.X;
p2.X = (int)Math.Ceiling(Math.Sqrt((double)bi[1])) - 1;
p2.Y = (bi[1] - p2.X * p2.X) % 2 == 0 ? 2 + 3 * p2.X - 1 : 2 + 3 * p2.X;
Console.WriteLine("p1.x={0} ,p2.x={1}", p1.X, p2.X);
p1.X = -p1.X + (bi[0] - p1.X * p1.X - 1);
p2.X = -p2.X + (bi[1] - p2.X * p2.X - 1);
//Console.WriteLine("p1.x={0} ,p1.y={1}", p1.X, p1.Y);
//Console.WriteLine("p2.x={0} ,p2.y={1}", p2.X, p2.Y);
Console.WriteLine("Ans={0}", Math.Round(((Math.Sqrt(((double)(p1.X - p2.X) * (double)(p1.X - p2.X)) + ((double)(p1.Y - p2.Y) / Math.Sqrt(3)) * (double)(p1.Y - p2.Y) / Math.Sqrt(3))) / 2),3).ToString("0.000"));
}
}
}
public class Point
{
private BigInteger _x, _y;
public BigInteger X
{
get { return _x; }
set { _x = value; }
}
public BigInteger Y
{
get { return _y; }
set { _y = value; }
}
}
}