Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Дачники__Контест_
- {
- class Program
- {
- static void Main(string[] args)
- {
- Square a, b;
- using (var sr = new StreamReader("input.txt"))
- {
- string[] str = sr.ReadLine().Split(' ');
- a = new Square(long.Parse(str[0]), long.Parse(str[1]), long.Parse(str[2]), long.Parse(str[3]));
- str = sr.ReadLine().Split(' ');
- b = new Square(long.Parse(str[0]), long.Parse(str[1]), long.Parse(str[2]), long.Parse(str[3]));
- //Console.WriteLine(a.Cross(b));
- //Console.ReadKey();
- }
- using (var sw = new StreamWriter("output.txt"))
- {
- if (a.Cross(b) == 0)
- {
- sw.Write($"0 0 {a.Inside(b)}");
- }
- else sw.Write($"1 {a.GetS(b)} {a.Inside(b)}");
- }
- }
- }
- class Square
- {
- #region Переменные
- public long pointX1, pointY1;
- public long pointX2, pointY2;
- private long __height, __width;
- public long height
- {
- get { return __height; }
- set
- {
- if (value < 0)
- {
- throw new ArgumentException("Ошибка ввода");
- }
- else __height = value;
- }
- }
- public long width
- {
- get { return __width; }
- set
- {
- if (value < 0)
- {
- throw new ArgumentException("Ошибка ввода");
- }
- else __width = value;
- }
- }
- #endregion
- #region Конструктор
- public Square(long x, long y, long w, long h)
- {
- this.pointX1 = x;
- this.pointY1 = y;
- this.width = w;
- this.height = h;
- this.pointX2 = pointX1 + this.width;
- this.pointY2 = pointY1 + this.height;
- }
- #endregion
- public int Cross(Square b)
- {
- Square temp;
- if (this.pointX1 > b.pointX1)
- {
- temp = new Square(b.pointX1, b.pointY1, b.width, b.height);
- b.pointX1 = this.pointX1;
- b.pointX2 = this.pointX2;
- b.pointY1 = this.pointY1;
- b.pointY2 = this.pointY2;
- this.pointX1 = temp.pointX1;
- this.pointX2 = temp.pointX2;
- this.pointY1 = temp.pointY1;
- this.pointY2 = temp.pointY2;
- }
- int count = 0;
- //if (this.pointY1 > b.pointY2 || this.pointX1 < b.pointX2 || b.pointX1 < this.pointX2 || b.pointY1 < this.pointY2)
- //{
- // count++;
- //}
- //else
- if(Math.Abs(b.pointY2 - this.pointY1) <= b.height + this.height && Math.Abs(b.pointX2 - this.pointX1) <= b.width + this.width)
- {
- count++;
- }
- return count;
- }
- public int Inside(Square b)
- {
- int temp = -1;
- if (b.pointX1 >= this.pointX1 && b.pointX2 <= this.pointX2 && b.pointY1 >= this.pointY1 && b.pointY2 <= this.pointY2)
- {
- temp = 1;
- }
- else if (b.pointX1 <= this.pointX1 && b.pointX2 >= this.pointX2 && b.pointY1 <= this.pointY1 && b.pointY2 >= this.pointY2)
- {
- temp = 0;
- }
- return temp;
- }
- public long GetS(Square b)
- {
- long c_a = Math.Max(this.pointX1, b.pointX1);
- long c_b = Math.Min(this.pointX2, b.pointX2);
- long c_c = Math.Min(this.pointY2, b.pointY2);
- long c_d = Math.Max(b.pointY1, this.pointY1);
- return Math.Abs((c_b - c_a) * (c_d - c_c));
- }
- }
- }
- /*
- Тест1
- 0 0 20 20
- -20 -30 20 20
- ans 0 0 -1
- Тест2
- -90 -20 180 40
- -20 -90 40 180
- ans 1 1600 -1
- Тест3
- -90 -20 180 40
- -20 0 40 90
- ans 1 800 -1
- Тест11
- -50 -50 50 50
- 0 0 50 50
- ans 1 0 -1
- Test21
- 0 0 10 10
- 0 -20 10 10
- ans 0 0 -1
- Test23
- 0 0 10 10
- -20 0 10 10
- ans 0 0 -1
- Test24
- 0 0 10 10
- 20 0 10 10
- ans 0 0 -1
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement