40 lines
682 B
C#
40 lines
682 B
C#
using System.Linq;
|
|
|
|
namespace magicSeries
|
|
{
|
|
public class Series
|
|
{
|
|
public readonly int[] Values;
|
|
|
|
public readonly int[] Occurrances;
|
|
|
|
public int Size { get { return Values.Length; } }
|
|
|
|
public Series(int size)
|
|
{
|
|
Values = new int[size];
|
|
Occurrances = new int[size + 1];
|
|
Occurrances[0] = size;
|
|
}
|
|
|
|
public int GetOccurrances(int i)
|
|
{
|
|
return Occurrances[i];
|
|
}
|
|
|
|
public bool IsFeasible()
|
|
{
|
|
for (var n = 0; n < Values.Count(); n++)
|
|
if (Values[n] != Occurrances[n])
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
public void UpdateValue(int n, int newValue)
|
|
{
|
|
Occurrances[Values[n]]--;
|
|
Occurrances[newValue]++;
|
|
Values[n] = newValue;
|
|
}
|
|
}
|
|
} |