Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@unilecs
Last active August 19, 2019 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unilecs/52cb63f4ef3d78005970a6c8327d0cf6 to your computer and use it in GitHub Desktop.
Save unilecs/52cb63f4ef3d78005970a6c8327d0cf6 to your computer and use it in GitHub Desktop.
Задача: игра Го
using System;
public class Program
{
public class Point
{
public int X;
public int Y;
public Point(int x, int y)
{
X = x;
Y = y;
}
}
private static void GetMaxArea(int N, int M, Point p1, Point p2)
{
int maxP1 = MaxAreaForFirstPoint(N, M, p1, p2);
int maxP2 = MaxAreaForFirstPoint(N, M, p2, p1);
Console.WriteLine(string.Format("Max Area = {0}", Math.Max(maxP1, maxP2)));
}
private static int MaxAreaForFirstPoint(int N, int M, Point p1, Point p2)
{
int result = 0;
if (p1.X < p2.X) { result = Math.Max(result, (p2.X - 1) * N); }
if (p1.X > p2.X) { result = Math.Max(result, (M - p2.X) * N); }
if (p1.Y < p2.Y) { result = Math.Max(result, (p2.Y - 1) * M); }
if (p1.Y > p2.Y) { result = Math.Max(result, (N - p2.Y) * M); }
return result;
}
public static void Main()
{
Console.WriteLine("UniLecs");
GetMaxArea(3, 4, new Point(2, 1), new Point(4, 3)); // 9
GetMaxArea(4, 6, new Point(5, 2), new Point(2, 3)); // 16
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment