Az alábbi letöltési lehetőségek közül választhatsz: (
segítség)
Típus: text/plain
Tartalmaz szöveget
Karakterkódolás: utf-8
Méret: 2 KB
using System;
using System.IO;
namespace Szuletesnap
{
class Program
{
const string InputFile = "szul00.be";
static int[] permutacio;
private static void Beolvas(string fileName)
{
using (StreamReader reader = new StreamReader(fileName))
{
int n = int.Parse(reader.ReadLine());
string[] szamok = reader.ReadLine().Split();
permutacio = new int[n];
for (int i = 0; i < n; i++)
permutacio[i] = int.Parse(szamok[i]);
}
}
private static void Torol(bool[] tomb)
{
if (tomb != null) {
for (int i = 0; i < tomb.Length; i++)
tomb[i] = false;
}
}
private static int MaxHamisHossz(bool[] tomb)
{
if (tomb == null)
throw new ArgumentNullException("tomb");
int kezdet = -1;
int maxHossz = 0;
int elsoIgaz = -1, utolsoIgaz = -1;
for (int i = 0; i < tomb.Length; i++) {
if (tomb[i]) {
kezdet = -1;
if (elsoIgaz == -1)
elsoIgaz = i;
utolsoIgaz = i;
}
else {
if (kezdet == -1)
kezdet = i;
int hossz = i - kezdet + 1;
if (maxHossz < hossz)
maxHossz = hossz;
}
}
int masikHossz = elsoIgaz + (tomb.Length - 1 - utolsoIgaz);
if (elsoIgaz != -1 && masikHossz > maxHossz)
return masikHossz;
else
return maxHossz;
}
private static int Megoldas()
{
if (permutacio == null || permutacio.Length == 0)
throw new InvalidOperationException("A permutáció tömb inicializálatlan!");
int n = permutacio.Length;
bool[] tavolsag = new bool[n];
int max1, max2;
Torol(tavolsag);
for (int i = 0; i < n; i++) {
int index = (i - permutacio[i] + n) % n;
tavolsag[index] = true;
}
max1 = MaxHamisHossz(tavolsag);
Torol(tavolsag);
for (int i = 0; i < n; i++) {
int index = (i - permutacio[n - i - 1] + n) % n;
tavolsag[index] = true;
}
max2 = MaxHamisHossz(tavolsag);
if (max1 > max2)
return (n - max1) / 2;
else
return (n - max2) / 2;
}
public static void Main(string[] args)
{
Beolvas(InputFile);
Console.WriteLine(Megoldas());
Console.ReadLine();
}
}
}