Skip to content

Instantly share code, notes, and snippets.

@BeautyfullCastle
Created October 7, 2020 15:59
Show Gist options
  • Save BeautyfullCastle/48dd9b49dc28e45e3f750d904667d572 to your computer and use it in GitHub Desktop.
Save BeautyfullCastle/48dd9b49dc28e45e3f750d904667d572 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
namespace PracticeAlgorithmCSharp
{
internal class Program
{
private static void Main(string[] args)
{
Solution();
}
private struct Vector
{
public double x;
public double y;
public Vector Normalized()
{
double length = Length();
return new Vector
{
x = x / length,
y = y / length
};
}
public double Length()
{
return Math.Sqrt(SqrLength());
}
public double SqrLength()
{
return Math.Abs(x * x + y * y);
}
public override string ToString()
{
return $"{x}, {y}";
}
public static Vector operator -(Vector a, Vector b)
=> new Vector { x = a.x - b.x, y = a.y - b.y };
}
public static void Solution()
{
var line = Console.ReadLine().Split(' ').Select((c) => int.Parse(c)).ToArray();
Vector mousePos = new Vector() { x = line[0], y = line[1] };
int r = line[2];
int d = line[3];
var targets = new Vector[]
{
new Vector { x = 0, y = 1 },
new Vector { x = -1, y = 1 },
new Vector { x = 1, y = 0 },
new Vector { x = -1, y = 0 },
new Vector { x = 0, y = -1 },
new Vector { x = -1, y = -1 },
new Vector { x = -2, y = 2 },
new Vector { x = -mousePos.x, y = -mousePos.y }
};
double rad = DegToRad(d);
int result = 0;
foreach (var target in targets)
{
if (target.SqrLength() > r * r)
{
continue;
}
Vector a = mousePos.Normalized();
Vector b = target.Normalized();
double dot = Dot(a, b);
double cos = Math.Cos(rad);
if (dot > cos)
{
++result;
Console.WriteLine(target);
}
}
Console.WriteLine(result);
}
private static double RadToDeg(double rad)
{
return (rad * 180.0 / Math.PI);
}
private static double DegToRad(double deg)
{
return (deg * Math.PI / 180.0);
}
private static double Dot(Vector a, Vector b)
{
return (a.x * b.x) + (a.y * b.y);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment