当前位置: 首页>>代码示例>>C#>>正文


C# Queue.Sum方法代码示例

本文整理汇总了C#中Queue.Sum方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.Sum方法的具体用法?C# Queue.Sum怎么用?C# Queue.Sum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Queue的用法示例。


在下文中一共展示了Queue.Sum方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Calculate

        public virtual IObservable<double> Calculate(IObservable<double> samples)
        {
            var q = new Queue<double>();
            var sma = double.NaN;

            return samples.Select(x =>
            {
                q.Enqueue(x);

                if (double.IsNaN(sma))
                {
                    sma = x;
                    return x;
                }

                if (q.Count <= N)
                {
                    sma = q.Sum() / q.Count;
                }
                else
                {
                    sma = sma + (x / N) - (q.Dequeue() / N);
                }

                return sma;
            });
        }
开发者ID:squaredinfinity,项目名称:Foundation,代码行数:27,代码来源:SimpleMovingAverage.cs

示例2: YieldSequence

        public IEnumerable<int> YieldSequence()
        {
            var queue = new Queue<int>();

            queue.Enqueue(1);
            yield return 1;

            while (true)
            {
                var next = queue.Sum();
                queue.Enqueue(next);

                if (queue.Count > 2)
                {
                    queue.Dequeue();
                }

                yield return next;
            }
        }
开发者ID:pmccloghrylaing,项目名称:numeric-sequencer,代码行数:20,代码来源:FibonacciSequencer.cs

示例3: Solve

        public static long Solve()
        {
            var longest = 0;
            var count = 0;
            var limit = 1000000;
            var primes = new PrimeNumbers(limit);
            var test = 0;
            var queue = new Queue<int>();

            foreach (var prime in primes)
            {
                test += prime;
                if (test >= limit)
                    break;

                queue.Enqueue(prime);

                if (primes.IsPrime(test) && queue.Count > count)
                {
                    longest = test;
                    count = queue.Count;
                }
            }

            while (!primes.IsPrime(test))
            {
                queue.Dequeue();
                test = queue.Sum();

                if (primes.IsPrime(test) && queue.Count > count)
                {
                    longest = test;
                    count = queue.Count;
                }
            }

            return longest;
        }
开发者ID:jonathascosta,项目名称:ProjectEuler,代码行数:38,代码来源:Problem050.cs

示例4: SendImpl

        private void SendImpl(Queue<string> stats)
        {
            try
            {
                if (Config.InternalStatsEnabled)
                {
                    PerfLogger.Gauge("Messages", stats.Count);
                    PerfLogger.Gauge("MessageSize", stats.Sum(s => s.Length));
                    var stopwatch = Stopwatch.StartNew();
                    _threadSafeUdpClient.Send(stats);
                    stopwatch.Stop();
                    PerfLogger.Timing("Send", stopwatch.ElapsedMilliseconds);
                }
                else
                {
                    _threadSafeUdpClient.Send(stats);
                }
            }
            catch (Exception e)
            {
                e.SetContext("stats", stats);
                e.SetContext("settings", _settings);
                Log.Error("Failed to send stats", e);

                if (Config.InternalStatsEnabled)
                {
                    PerfLogger.Increment("Error");
                }
            }
        }
开发者ID:drewburlingame,项目名称:Perfadilly,代码行数:30,代码来源:StatsdPerfLoggerAppender.cs

示例5: FindSubtreeByGivenSum

        private static void FindSubtreeByGivenSum(int neededSum)
        {
            foreach (var node in nodeByValue.Values)
            {
                var queue = new Queue<int>();
                InOrderTraverse(node, queue);

                if (queue.Sum() == neededSum)
                {
                    subtreeWhitGivenSum.Add(string.Join(" + ", queue));
                }
            }
        }
开发者ID:pavelilchev,项目名称:HomeWorks,代码行数:13,代码来源:PlayWithTrees.cs

示例6: AustraliaRuleZ

        private int AustraliaRuleZ(TurnManager turnManager, RiskAnalysis analysis, int availableTroops)
        {
            if (availableTroops == 0) return 0;
            var downUnder = analysis.Continents.FirstOrDefault(x => x.Name == EContinent.Australia);
            if (downUnder == null || downUnder.MyCountries.Count == 0)
                return 0;

            if (downUnder.IsOwned)
            {
                availableTroops = Math.Min(availableTroops, 3);
                var whatchamacallit = downUnder.MyCountries.First(x => x.IsContinentGateway());
                var minAussieDefenders = 6;
                if (whatchamacallit.IsUnderAttack() || whatchamacallit.NumberOfTroops < minAussieDefenders)
                {
                    analysis.Deployments.Add(new Deployment(turnManager)
                        {
                            ToCountry = whatchamacallit,
                            Troops = availableTroops,

                        });
                    return availableTroops;
                }
                var thingamajig = whatchamacallit.AdjacentCountries.First(x => x.Continent != EContinent.Australia);
                if (thingamajig.IsUnderAttack() || thingamajig.NumberOfTroops < minAussieDefenders)
                {
                    analysis.Deployments.Add(new Deployment(turnManager)
                    {
                        ToCountry = thingamajig,
                        Troops = availableTroops,

                    });
                    return availableTroops;
                }

                return 0;
            }

            var deployments = downUnder.MyCountries.Select(x => new Deployment(turnManager) { ToCountry = x });
            // round-robin deployment, using a queue...
            var q = new Queue<Deployment>(deployments);
            while (availableTroops > 0)
            {
                availableTroops--;
                var c = q.Dequeue();
                c.Troops++;
                q.Enqueue(c);
            }
            analysis.Deployments.AddRange(q);
            return q.Sum(x => x.Troops);
        }
开发者ID:resc,项目名称:Risk,代码行数:50,代码来源:RiskAnalyzer.cs

示例7: RescueLastManStanding

        private int RescueLastManStanding(TurnManager turnManager, RiskAnalysis analysis, int availableTroops)
        {
            if (availableTroops < 4) return 0;

            var lastManStanding = new Queue<Deployment>(from cnt in analysis.Continents
                                                        where cnt.MyCountries.Sum(x => x.NumberOfTroops) < 3
                                                        from c in cnt.MyCountries
                                                        select
                                                            new Deployment(turnManager)
                                                                {
                                                                    ToCountry = c
                                                                });
            if (lastManStanding.Count == 0)
                return 0;

            while (availableTroops > 0)
            {
                availableTroops--;
                var x = lastManStanding.Dequeue();
                x.Troops++;
                lastManStanding.Enqueue(x);
            }
            analysis.Deployments.AddRange(lastManStanding);
            return lastManStanding.Sum(x => x.Troops);
        }
开发者ID:resc,项目名称:Risk,代码行数:25,代码来源:RiskAnalyzer.cs


注:本文中的Queue.Sum方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。