結果
| 問題 |
No.275 中央値を求めよ
|
| コンテスト | |
| ユーザー |
FF256grhy
|
| 提出日時 | 2015-09-04 22:54:49 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 1,000 ms |
| コード長 | 582 bytes |
| コンパイル時間 | 213 ms |
| コンパイル使用メモリ | 23,808 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-24 23:10:11 |
| 合計ジャッジ時間 | 1,220 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:6:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
6 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:10:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | scanf("%d", &temp);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include <stdio.h>
int n, a[2001];
int main(void) {
scanf("%d", &n);
int i;
for(i = 0; i < n; i++) {
int temp;
scanf("%d", &temp);
a[temp + 1000]++;
}
int c = 0, flag = 0, ans = 0;
for(i = 0; i < 2001; i++) {
c += a[i];
if(a[i]) {
if(n % 2 == 1) {
if(c > n / 2) {
ans = 2 * (i - 1000);
break;
}
} else {
if(flag == 0 && c > n / 2) {
ans = 2 * (i - 1000);
break;
}
if(c >= n / 2) {
ans += i - 1000;
if(flag == 0) { flag = 1; } else { break; }
}
}
}
}
printf("%f\n", ans / 2.0 );
return 0;
}
FF256grhy