Advertisement
StreetKatya

Дачники

Oct 28th, 2021
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.46 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Дачники__Контест_
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Square a, b;
  15.             using (var sr = new StreamReader("input.txt"))
  16.             {
  17.                 string[] str = sr.ReadLine().Split(' ');
  18.                 a = new Square(long.Parse(str[0]), long.Parse(str[1]), long.Parse(str[2]), long.Parse(str[3]));
  19.                 str = sr.ReadLine().Split(' ');
  20.                 b = new Square(long.Parse(str[0]), long.Parse(str[1]), long.Parse(str[2]), long.Parse(str[3]));
  21.                 //Console.WriteLine(a.Cross(b));
  22.                 //Console.ReadKey();
  23.             }
  24.             using (var sw = new StreamWriter("output.txt"))
  25.             {
  26.                 if (a.Cross(b) == 0)
  27.                 {
  28.                     sw.Write($"0 0 {a.Inside(b)}");
  29.                 }
  30.                 else sw.Write($"1 {a.GetS(b)} {a.Inside(b)}");
  31.             }
  32.         }
  33.  
  34.     }
  35.     class Square
  36.     {
  37.         #region Переменные
  38.         public long pointX1, pointY1;
  39.         public long pointX2, pointY2;
  40.         private long __height, __width;
  41.         public long height
  42.         {
  43.             get { return __height; }
  44.             set
  45.             {
  46.                 if (value < 0)
  47.                 {
  48.                     throw new ArgumentException("Ошибка ввода");
  49.                 }
  50.                 else __height = value;
  51.             }
  52.         }
  53.         public long width
  54.         {
  55.             get { return __width; }
  56.             set
  57.             {
  58.                 if (value < 0)
  59.                 {
  60.                     throw new ArgumentException("Ошибка ввода");
  61.                 }
  62.                 else __width = value;
  63.             }
  64.         }
  65.         #endregion
  66.         #region Конструктор
  67.         public Square(long x, long y, long w, long h)
  68.         {
  69.             this.pointX1 = x;
  70.             this.pointY1 = y;
  71.             this.width = w;
  72.             this.height = h;
  73.             this.pointX2 = pointX1 + this.width;
  74.             this.pointY2 = pointY1 + this.height;
  75.         }
  76.         #endregion
  77.         public int Cross(Square b)
  78.         {
  79.             Square temp;
  80.             if (this.pointX1 > b.pointX1)
  81.             {
  82.                 temp = new Square(b.pointX1, b.pointY1, b.width, b.height);
  83.                 b.pointX1 = this.pointX1;
  84.                 b.pointX2 = this.pointX2;
  85.                 b.pointY1 = this.pointY1;
  86.                 b.pointY2 = this.pointY2;
  87.                 this.pointX1 = temp.pointX1;
  88.                 this.pointX2 = temp.pointX2;
  89.                 this.pointY1 = temp.pointY1;
  90.                 this.pointY2 = temp.pointY2;
  91.             }
  92.             int count = 0;
  93.             //if (this.pointY1 > b.pointY2 || this.pointX1 < b.pointX2 || b.pointX1 < this.pointX2 || b.pointY1 < this.pointY2)
  94.             //{
  95.             //    count++;
  96.             //}
  97.             //else
  98.             if(Math.Abs(b.pointY2 - this.pointY1) <= b.height + this.height && Math.Abs(b.pointX2 - this.pointX1) <= b.width + this.width)
  99.             {
  100.                 count++;
  101.             }
  102.             return count;
  103.         }
  104.         public int Inside(Square b)
  105.         {
  106.             int temp = -1;
  107.             if (b.pointX1 >= this.pointX1 && b.pointX2 <= this.pointX2 && b.pointY1 >= this.pointY1 && b.pointY2 <= this.pointY2)
  108.             {
  109.                 temp = 1;
  110.             }
  111.             else if (b.pointX1 <= this.pointX1 && b.pointX2 >= this.pointX2 && b.pointY1 <= this.pointY1 && b.pointY2 >= this.pointY2)
  112.             {
  113.                 temp = 0;
  114.             }
  115.             return temp;
  116.         }
  117.         public long GetS(Square b)
  118.         {
  119.             long c_a = Math.Max(this.pointX1, b.pointX1);
  120.             long c_b = Math.Min(this.pointX2, b.pointX2);
  121.             long c_c = Math.Min(this.pointY2, b.pointY2);
  122.             long c_d = Math.Max(b.pointY1, this.pointY1);
  123.             return Math.Abs((c_b - c_a) * (c_d - c_c));
  124.         }
  125.     }
  126. }
  127.  
  128. /*
  129. Тест1
  130. 0 0 20 20
  131. -20 -30 20 20
  132. ans 0 0 -1
  133. Тест2
  134. -90 -20 180 40
  135. -20 -90 40 180
  136. ans 1 1600 -1
  137. Тест3
  138. -90 -20 180 40
  139. -20 0 40 90
  140. ans 1 800 -1
  141. Тест11
  142. -50 -50 50 50
  143. 0 0 50 50
  144. ans 1 0 -1
  145. Test21
  146. 0 0 10 10
  147. 0 -20 10 10
  148. ans 0 0 -1
  149. Test23
  150. 0 0 10 10
  151. -20 0 10 10
  152. ans 0 0 -1
  153. Test24
  154. 0 0 10 10
  155. 20 0 10 10
  156. ans 0 0 -1
  157. */
  158.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement