Home

Archivos

Buscar

Categorías

Feeds:

RSS / Atom

TopCoder SRM 431· 23. December 2008, 23:59

Participé en vivo por primera vez, y ya tenía el de 500 jalando en mi máquina pero no alcancé a subirlo porque me tardé mucho debugeando una tonteria en el de 250 y además el MSN no me dejó en paz.

    class MegaCoolNumbersEasy
    {
        public static int count(int N)
        {
            string st = N.ToString();
            int c=0;
            for(int i=1;i<N+1;i++)
            {
                if (check(i.ToString()))
                {
                    System.Diagnostics.Debug.WriteLine(i);
                    c++;
                }
            }
            return c;
        }
        public static bool check(string st_n)
        {
            if (st_n.Length<3) 
                return true;
            int dif = -10;
            int last = -10;
            foreach (char c in st_n)
            {
                if (last == -10)
                {
                    last = (int)c;
                }
                else
                {
                    if (dif==-10)
                    {
                        dif=(int)c-last;
                        last=(int)c;
                    }
                    else
                    {
                        int newdif = (int)c - last;
                        if (newdif != dif)
                            return false;
                        dif = newdif;
                        last = (int)c;
                    }
                }
            }
            return true;
        }
    }
    class FallingPoints
    {
        public static double[] getHeights(int[] X, int R)
        {
            List<double> l = new List<double>();
            l.Add(0.0);
            for (int i = 1; i < X.Length; i++)
            {
                int x1 = X[i-1];
                double y1 = l.Last();
                int x2 = X[i];
                double discriminante=(R * R) - Math.Pow((x2 - x1), 2.0);
                if (discriminante<0)
                    l.Add(0.0);
                else
                    l.Add(Math.Sqrt(discriminante) + y1);
            }
            return l.ToArray();
        }
    }