Codeforces Round #183 (Div. 1) / 303A Lucky Permutation Triple (強大的數學&想法題)

http://codeforces.com/problemset/problem/303/A

  • when n is odd, A[i] = B[i] = i
  • when n is even, there is no solution.
  • why? I, then  or just , where S = 0 + 1 + ... + n - 1 = n(n - 1) / 2. So, there must be . But when n is even, .
/*92ms,0KB*/

#include <iostream>
using namespace std;

int main()
{
	int n;
	cin >> n;
	if (n & 1) 
	{
		for (int i = 0; i < n; i++) cout << i << " ";
		cout << endl;
		for (int i = 0; i < n; i++) cout << i << " ";
		cout << endl;
		for (int i = 0; i < n; i++) cout << (2 * i) % n << " ";
		cout << endl;
	}
	else cout << -1 << endl;
	return 0;
}

【額外思考】
另一種構造方法如下,並且還滿足了一個要求:
當n爲奇數時,若要求AB兩個排列不一樣,怎麼做?
可以把A序列設爲n-1,n-2,n-3,...,1,0(公差爲-1)
然後B序列設爲0,2,4,...,1,3,5,...(公差爲2)
這樣C序列就是n-1,0,1,2,...(公差爲1)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章