Sunday, December 14, 2014

Topcoder Single Round Match 591 Round 1 - Division II, Level One

// Topcoder Single Round Match 591 Round 1 - Division II, Level One

using System;
using System.Collections.Generic;
using System.Linq;

public class TheArithmeticProgression
{
    public double minimumChange ( int a, int b, int c )
    {
        double bb = ( a + c ) / 2.0;
        double aa = 2 * b - c;
        double cc = 2 * b - a;
        double ans = double.MaxValue;
        double r = Math.Abs ( bb - b );
        ans = Math.Min ( ans, r );
        r = Math.Abs ( aa - a );
        ans = Math.Min ( ans, r );
        r = Math.Abs ( cc - c );
        ans = Math.Min ( ans, r );
        return ans;
    }

    static void Main ( string[] args ) { }
}

No comments:

Post a Comment