Skip to content

Instantly share code, notes, and snippets.

@unilecs unilecs/GetMaxArea.cs Secret
Last active Aug 19, 2019

Embed
What would you like to do?
Задача: игра Го
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
You can’t perform that action at this time.