示例#1
0
        private static string majorElement(star canidate, HashSet <star> stars)
        {
            int i = 0;
            int c = 0;
            int k = stars.Count;

            if (canidate == null)
            {
                return("No");
            }
            else
            {
                foreach (star el in stars)
                {
                    if (canidate.distanceSQRD(el) <= distanceSQRD)
                    {
                        c++;
                    }
                    else
                    {
                        i++;
                    }
                }
                if (c > k / 2)
                {
                    return(c.ToString());
                }
                else
                {
                    return("No");
                }
            }
        }
示例#2
0
        private static string foo2(HashSet <star> stars)
        {
            star canidate = null;
            int  c        = 0;

            foreach (star el in stars)
            {
                if (c == 0)
                {
                    canidate = el;
                    c        = 1;
                }
                else if (canidate.distanceSQRD(el) <= distanceSQRD)
                {
                    c++;
                }
                else
                {
                    c--;
                }
            }
            if (c == 0)
            {
                return("NO");
            }
            else
            {
                c = 0;
                foreach (star el in stars)
                {
                    if (canidate.distanceSQRD(el) <= distanceSQRD)
                    {
                        c++;
                    }
                }
                if (c > stars.Count / 2)
                {
                    return(c.ToString());
                }
                else
                {
                    return("NO");
                }
            }
        }