結果

問題 No.275 中央値を求めよ
ユーザー tetora1011tetora1011
提出日時 2019-11-16 18:01:30
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 41 ms / 1,000 ms
コード長 6,660 bytes
コンパイル時間 2,134 ms
コンパイル使用メモリ 123,204 KB
実行使用メモリ 28,368 KB
最終ジャッジ日時 2024-09-25 02:17:55
合計ジャッジ時間 4,561 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #
プレゼンテーションモードにする

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace No275
{
class Program
{
public static void Solve(Input input)
{
var n = input.NextInt();
var a = input.NextInt(n);
Array.Sort(a);
double m;
if (a.Length == 1)
{
m = a[0];
}
else if (a.Length % 2 == 0)
{
m = a.Skip(a.Length / 2 - 1).Take(2).Average();
}
else
{
m = a[a.Length / 2];
}
Console.WriteLine($"{m:F10}");
}
#region Main
public static void Main(string[] args)
{
//
// TLE
var needsFlushOutput = true;
if (needsFlushOutput)
{
//
var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
// path
var input = new Input();
//
// ……
#if DEBUG
input.SetText("");
#endif
Solve(input);
Console.Out.Flush();
}
#endregion
#region Competitive Template
#pragma warning disable CS0414
static readonly int MOD = (int)1e9 + 7;
static readonly int[] dx = { 1, 0, -1, 0 };
static readonly int[] dy = { 0, 1, 0, -1 };
/// <summary> </summary>
static readonly char[] dir = { 'R', 'U', 'L', 'D' };
#pragma warning restore CS0414
public class Input
{
//
//
static readonly char[] separator = { ' ', '\r', '\n' };
readonly StreamReader sr;
readonly Queue<string> queue;
/// <summary>
/// path
/// </summary>
public Input(string path = "")
{
queue = new Queue<string>();
if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); }
else { sr = new StreamReader(path); }
}
/// <summary>
///
/// </summary>
public void SetText(IEnumerable<string> items)
{
foreach (var item in items)
SetText(item);
}
/// <summary>
///
/// </summary>
public bool SetText(string s)
{
if (string.IsNullOrEmpty(s)) return false;
foreach (var elem in s.Trim().Split(separator, StringSplitOptions.RemoveEmptyEntries))
queue.Enqueue(elem);
return true;
}
/// <summary>
///
/// </summary>
public bool Any() => queue.Any() || Read();
/// <summary>
/// queuesplit
/// </summary>
bool Read()
{
if (!SetText(sr.ReadLine())) return false;
if (!queue.Any()) return Read();
return queue.Any();
}
/// <summary>
/// string
/// </summary>
public string Next()
{
if (!queue.Any() && !Read()) return "";
return queue.Dequeue();
}
/// <summary>
/// queueenqueue
/// </summary>
bool Accumulate(int n)
{
while (queue.Count() < n)
if (!Read()) return false;
return true;
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
/// <summary>
/// nparseoffsetadd
/// </summary>
T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add)
{
if (!Accumulate(n)) return null;
var a = new T[n];
for (int i = 0; i < n; i++)
a[i] = add(parse(queue.Dequeue()), offset);
return a;
}
public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x);
public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y);
public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y);
public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y);
}
static class Utils
{
public static T Max<T>(params T[] objs) => objs.Max();
public static T Min<T>(params T[] objs) => objs.Min();
/// <summary>
/// vfillT[d1][d2]
/// </summary>
public static T[][] Create2DArray<T>(int d1, int d2, T v)
{
return
Enumerable.Repeat(0, d1).Select(_ =>
Enumerable.Repeat(v, d2).ToArray()).ToArray();
}
/// <summary>
/// vfillT[d1][d2][d3]
/// </summary>
public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v)
{
return
Enumerable.Repeat(0, d1).Select(_ =>
Enumerable.Repeat(0, d2).Select(__ =>
Enumerable.Repeat(v, d3).ToArray()).ToArray()).ToArray();
}
}
#endregion
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0