BorislavBorisov

08.01.Teleport points авторско

Feb 27th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. class TeleportPoints
  4. {
  5.     static void Main()
  6.     {
  7.         string[] pointA = Console.ReadLine().Split(' ');
  8.         string[] pointB = Console.ReadLine().Split(' ');
  9.         string[] pointC = Console.ReadLine().Split(' ');
  10.         string[] pointD = Console.ReadLine().Split(' ');
  11.  
  12.         double radius = double.Parse(Console.ReadLine());
  13.         double step = double.Parse(Console.ReadLine());
  14.  
  15.         double aX = double.Parse(pointA[0]);
  16.         double aY = double.Parse(pointA[1]);
  17.         double bX = double.Parse(pointB[0]);
  18.         double bY = double.Parse(pointB[1]);
  19.         double cX = double.Parse(pointC[0]);
  20.         double cY = double.Parse(pointC[1]);
  21.         double dX = double.Parse(pointD[0]);
  22.         double dY = double.Parse(pointD[1]);
  23.  
  24.         int pointCounter = 0;
  25.  
  26.         //Check the right side
  27.         for (double x = 0; x <= radius; x += step)
  28.         {
  29.             //Upper quadrant
  30.             for (double y = 0; y <= radius; y += step)
  31.             {
  32.                 if ((Math.Pow(x - 0, 2) + Math.Pow(y - 0, 2)) <= Math.Pow(radius, 2))
  33.                 {
  34.                     if ((x > aX && x < bX) && (y < cY && y > bY))
  35.                     {
  36.                         pointCounter++;
  37.                     }
  38.                 }
  39.             }
  40.  
  41.             //Lower quadrant
  42.             for (double y = -step; y >= -radius; y -= step)
  43.             {
  44.                 if ((Math.Pow(x - 0, 2) + Math.Pow(y - 0, 2)) <= Math.Pow(radius, 2))
  45.                 {
  46.                     if ((x > aX && x < bX) && (y < cY && y > bY))
  47.                     {
  48.                         pointCounter++;
  49.                     }
  50.                 }
  51.             }
  52.  
  53.         }
  54.  
  55.         //Check the left side
  56.         for (double x = -step; x >= -radius; x -= step)
  57.         {
  58.             //Upper quadrant
  59.             for (double y = 0; y <= radius; y += step)
  60.             {
  61.                 if ((Math.Pow(x - 0, 2) + Math.Pow(y - 0, 2)) <= Math.Pow(radius, 2))
  62.                 {
  63.                     if ((x > aX && x < bX) && (y < cY && y > bY))
  64.                     {
  65.                         pointCounter++;
  66.                     }
  67.                 }
  68.             }
  69.  
  70.             //Lower quadrant
  71.             for (double y = -step; y >= -radius; y -= step)
  72.             {
  73.                 if ((Math.Pow(x - 0, 2) + Math.Pow(y - 0, 2)) <= Math.Pow(radius, 2))
  74.                 {
  75.                     if ((x > aX && x < bX) && (y < cY && y > bY))
  76.                     {
  77.                         pointCounter++;
  78.                     }
  79.                 }
  80.             }
  81.         }
  82.  
  83.         Console.WriteLine(pointCounter);
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment