Exemplo n.º 1
0
        void Solve()
        {
            this.wr = new Writer(this.isReactive);
            //this.wr = new Writer(this.outFilePath);
#if DEBUG
            if (!this.isReactive)
            {
                this.sc = new Scanner(this.inFilePath);
            }
            else
            {
                this.sc = new Scanner();
            }
#else
            this.sc = new Scanner();
#endif

            N = sc.NextInt;
            t = new int[N].Select(el => sc.NextInt).ToArray();
            v = new int[N].Select(el => sc.NextInt).ToArray();
            r = new double[N + 1];
            for (int i = 1; i < N; i++)
            {
                r[i] = Math.Min(v[i - 1], v[i]);
            }
            r[0] = r[N] = 0;
            for (int i = 0; i < N; i++)
            {
                r[i + 1] = Math.Min(r[i + 1], r[i] + t[i]);
            }
            for (int i = N; i > 0; i--)
            {
                r[i - 1] = Math.Min(r[i - 1], r[i] + t[i - 1]);
            }
            double ans = 0;
            for (int i = 0; i < N; i++)
            {
                double buf = 0;
                double low = 0, high = t[i];
                double ma;
                for (int j = 0; j < 100; j++)
                {
                    double mid = (low + high) / 2;
                    ma = r[i] + mid;
                    if (ma > v[i])
                    {
                        high = mid;
                    }
                    else
                    {
                        if (ma - (t[i] - mid) <= r[i + 1])
                        {
                            low = mid;
                        }
                        else
                        {
                            high = mid;
                        }
                    }
                }
                double upTime = low;
                ma = r[i] + upTime;
                double downTime = ma - r[i + 1];
                buf  = (r[i] + ma) * upTime / 2;
                buf += (ma + r[i + 1]) * downTime / 2;
                buf += (t[i] - upTime - downTime) * ma;
                ans += buf;
            }
            wr.WriteLine(ans);
        }
Exemplo n.º 2
0
        void MakeTestCase()
        {
            Random rand = new Random();

            this.wr = new Writer(inFilePath);
        }