Codeforces #179 Div2 A "Yaroslav and Permutations"
問題
http://codeforces.com/contest/296/problem/A
訳
長さNの整数の配列がある。1秒間ごとに、2つの隣り合う要素の値を交換する。
隣り合う要素の値が違うような配列を作る事を目指しているのだが、
いつかその時はくるだろうか?
制約
1 <= N <= 100
1 <= 配列の値 <= 1000
考えた事
1秒間ごとに、2つの隣り合う要素の値を交換する
とはつまり。。
自由に並べ替える事が出来る。
ある数を1つ飛ばしに置いてっても入りきらなければダメ
ソースコード
int main() { int N, a[1001]; cin >> N; memset( a, 0, sizeof(a) ); for( int i = 0; i < N; i++ ){ int t; cin >> t; a[t]++; } bool ok = true; int okNum = (N - 1) / 2 + 1; for( int i = 1; i <= 1000; i++ ){ if( okNum < a[i] ) ok = false; } cout << (ok ? "YES" : "NO") << endl; }