Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Teleportation
- {
- class TeleportationMain
- {
- static void Main(string[] args)
- {
- double[] aCoordinates = Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray();
- var A = new Point(aCoordinates[0], aCoordinates[1]);
- double[] bCoordinates = Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray();
- var B = new Point(bCoordinates[0], bCoordinates[1]);
- double[] cCoordinates = Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray();
- var C = new Point(cCoordinates[0], cCoordinates[1]);
- double[] dCoordinates = Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray();
- var D = new Point(dCoordinates[0], dCoordinates[1]);
- var Rectangle = new List<Point>();
- Rectangle.Add(A);
- Rectangle.Add(B);
- Rectangle.Add(C);
- Rectangle.Add(D);
- double radius = double.Parse(Console.ReadLine());
- double step = double.Parse(Console.ReadLine());
- double AB = Math.Sqrt((aCoordinates[0] - bCoordinates[0]) * (aCoordinates[0] - bCoordinates[0]) + (aCoordinates[1] - bCoordinates[1]) * (aCoordinates[1] - bCoordinates[1]));
- double BC = Math.Sqrt((cCoordinates[0] - bCoordinates[0]) * (cCoordinates[0] - bCoordinates[0]) + (cCoordinates[1] - bCoordinates[1]) * (cCoordinates[1] - bCoordinates[1]));
- double AD = Math.Sqrt((dCoordinates[0] - aCoordinates[0]) * (dCoordinates[0] - aCoordinates[0]) + (dCoordinates[1] - aCoordinates[1]) * (dCoordinates[1] - aCoordinates[1]));
- double CD = Math.Sqrt((cCoordinates[0] - dCoordinates[0]) * (cCoordinates[0] - dCoordinates[0]) + (cCoordinates[1] - dCoordinates[1]) * (cCoordinates[1] - dCoordinates[1]));
- int count = 0;
- for (double X = step; X < radius; X += step)
- {
- for (double Y = step; Y < radius; Y += step)
- {
- var point = new Point(X, Y);
- if (point.PointInsideACircle(radius))
- {
- if (point.PointInsideARectangle(Rectangle, AB, BC, CD, AD))
- {
- count++;
- }
- }
- point = new Point(-X, -Y);
- if (point.PointInsideACircle(radius))
- {
- if (point.PointInsideARectangle(Rectangle, AB, BC, CD, AD))
- {
- count++;
- }
- }
- point = new Point(X, -Y);
- if (point.PointInsideACircle(radius))
- {
- if (point.PointInsideARectangle(Rectangle, AB, BC, CD, AD))
- {
- count++;
- }
- }
- point = new Point(-X, Y);
- if (point.PointInsideACircle(radius))
- {
- if (point.PointInsideARectangle(Rectangle, AB, BC, CD, AD))
- {
- count++;
- }
- }
- point = new Point(0, -Y);
- if (point.PointInsideACircle(radius))
- {
- if (point.PointInsideARectangle(Rectangle, AB, BC, CD, AD))
- {
- count++;
- }
- }
- point = new Point(0, Y);
- if (point.PointInsideACircle(radius))
- {
- if (point.PointInsideARectangle(Rectangle, AB, BC, CD, AD))
- {
- count++;
- }
- }
- point = new Point(-X, 0);
- if (point.PointInsideACircle(radius))
- {
- if (point.PointInsideARectangle(Rectangle, AB, BC, CD, AD))
- {
- count++;
- }
- }
- point = new Point(X, 0);
- if (point.PointInsideACircle(radius))
- {
- if (point.PointInsideARectangle(Rectangle, AB, BC, CD, AD))
- {
- count++;
- }
- }
- }
- }
- Console.WriteLine(count);
- }
- class Point
- {
- public double X { get; set; }
- public double Y { get; set; }
- public Point(double x, double y)
- {
- this.X = x;
- this.Y = y;
- }
- public void ResetPoint()
- {
- this.X = 0;
- this.Y = 0;
- }
- public bool PointInsideACircle(double radius)
- {
- return ((this.X - 0) * (this.X - 0) + (this.Y - 0) * (this.Y - 0)) < radius * radius;
- }
- public bool PointInsideARectangle(List<Point> points, double AB, double BC, double CD, double AD)
- {
- double AX = Math.Sqrt((this.X - points[0].X) * (this.X - points[0].X) + (this.Y - points[0].Y) * (this.Y - points[0].Y));
- double BX = Math.Sqrt((this.X - points[1].X) * (this.X - points[1].X) + (this.Y - points[1].Y) * (this.Y - points[1].Y));
- double CX = Math.Sqrt((this.X - points[2].X) * (this.X - points[2].X) + (this.Y - points[2].Y) * (this.Y - points[2].Y));
- double DX = Math.Sqrt((this.X - points[3].X) * (this.X - points[3].X) + (this.Y - points[3].Y) * (this.Y - points[3].Y));
- double p = (AX + BX + AB) / 2;
- double areaAXB = Math.Sqrt(p * (p - AX) * (p - BX) * (p - AB));
- p = (BX + CX + BC) / 2;
- double areaBXC = Math.Sqrt(p * (p - CX) * (p - BX) * (p - BC));
- p = (CD + CX + DX) / 2;
- double areaCXD = Math.Sqrt(p * (p - CX) * (p - DX) * (p - CD));
- p = (AD + AX + DX) / 2;
- double areaDXA = Math.Sqrt(p * (p - AX) * (p - DX) * (p - AD));
- double rectArea = AB * BC;
- if (rectArea > areaAXB + areaBXC + areaCXD + areaDXA)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement