Last active
December 18, 2015 13:29
-
-
Save briandiaz/5790410 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace SuperConjunto_Dinapoles | |
{ | |
class Punto | |
{ | |
public int X { get; set; } | |
public int Y { get; set; } | |
public Punto(int X, int Y) | |
{ | |
this.X = X; | |
this.Y = Y; | |
} | |
public bool verificarLineaVertical(Punto P) | |
{ | |
int X1 = this.X; | |
int Y1 = this.Y; | |
int X2 = P.X, Y2 = P.Y; | |
return (X1 == X2 || (X1 == X2 && Y1 == Y2)) ? true : false; | |
} | |
public bool verificarLineaHorizontal(Punto P) | |
{ | |
int X1 = this.X; | |
int Y1 = this.Y; | |
int X2 = P.X, Y2 = P.Y; | |
return (Y1 == Y2 || (X1 == X2 && Y1 == Y2)) ? true : false; | |
} | |
} | |
class Program | |
{ | |
public static List<Punto> Dinapoles(List<Punto> listaPuntos) | |
{ | |
List<Punto> resultado = listaPuntos; | |
Random rnd = new Random(); | |
Punto puntoresultante; | |
for (int i = 0; i < listaPuntos.Count(); i++) | |
{ | |
if (i < listaPuntos.Count() - 1) | |
{ | |
if (listaPuntos[i].verificarLineaVertical(listaPuntos[i + 1]) && | |
listaPuntos[i].verificarLineaHorizontal(listaPuntos[i + 1])) | |
{ | |
// Son iguales no hago nada. | |
// No se puede. | |
continue; | |
} | |
else if(listaPuntos[i].verificarLineaVertical(listaPuntos[i + 1])) // Mismo X | |
{ | |
// Si ambos están en el mismo eje X entonces el eje Y del punto resultante es el Y del primero y el X es un aleatorio de - X a X del punto 2. | |
puntoresultante = new Punto(rnd.Next(-listaPuntos[i + 1].X, listaPuntos[i + 1].X), listaPuntos[i].Y); | |
resultado.Add(puntoresultante); | |
break; | |
} | |
else if (listaPuntos[i].verificarLineaHorizontal(listaPuntos[i + 1])) // Mismo Y | |
{ | |
// Si ambos están en el mismo eje Y entonces el eje X del punto resultante es el X del primero y el Y es un aleatorio de - Y a Y del punto 2. | |
puntoresultante = new Punto(listaPuntos[i].X, rnd.Next(-listaPuntos[i+1].Y, listaPuntos[i+1].Y)); | |
resultado.Add(puntoresultante); | |
break; | |
} | |
else | |
{ | |
if (listaPuntos[i].Y > listaPuntos[i + 1].Y) | |
{ | |
//El eje Y es la diferencia del eje Y del Punto 2 con Punto 1 sumado con el eje y del Punto 2. | |
puntoresultante = new Punto(listaPuntos[i].X, listaPuntos[i + 1].Y + (listaPuntos[i].Y - listaPuntos[i + 1].Y)); | |
} | |
else | |
{ | |
//El eje Y es la diferencia del eje Y del Punto 1 con Punto 2 sumado con el eje y del Punto 1. | |
puntoresultante = new Punto(listaPuntos[i].X, listaPuntos[i].Y + (listaPuntos[i + 1].Y - listaPuntos[i].Y)); | |
} | |
if (coincidenciaPuntos(puntoresultante, listaPuntos[i]) || coincidenciaPuntos(puntoresultante, listaPuntos[i+1])) | |
{ | |
// Este es el punto que buscamos. | |
resultado.Add(puntoresultante); | |
break; | |
} | |
else | |
{ | |
// Punto X y Punto Y son aleatorios. | |
puntoresultante = new Punto(rnd.Next(-listaPuntos[i].X,listaPuntos[i].X),rnd.Next(listaPuntos[i+1].Y,listaPuntos[i+1].Y)); | |
} | |
} | |
} | |
} | |
return resultado; | |
} | |
public static bool coincidenciaPuntos(Punto p1, Punto p2) | |
{ | |
// * Los dos puntos estan en la misma línea vertical | |
// * o | |
// * Los dos puntos estan en la misma línea horizontal | |
return ((p1.verificarLineaHorizontal(p2) || p1.verificarLineaVertical(p2))) ? true : false; | |
} | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Entrada: "); | |
int N = int.Parse(Console.ReadLine()); | |
List<Punto> listaPuntos = new List<Punto>(); | |
Punto punto; | |
int X, Y; | |
for (int i = 0; i < N; i++) | |
{ | |
String[] puntos = Console.ReadLine().Split(' '); | |
X = int.Parse(puntos[0]); | |
Y = int.Parse(puntos[1]); | |
punto = new Punto(X, Y); | |
listaPuntos.Add(punto); | |
} | |
Console.WriteLine("Salida: "); | |
List<Punto> listaPuntosRes = Dinapoles(listaPuntos); | |
Console.WriteLine(listaPuntosRes.Count()); | |
foreach (Punto p in listaPuntosRes.OrderBy(x=>x.X).ThenBy(y=>y.Y)) // Imprimir todos los Puntos ordenados por el conjunto de su eje X y eje Y. | |
{ | |
Console.WriteLine("{1} {2}", listaPuntosRes.IndexOf(p) + 1, p.X, p.Y); | |
} | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment