标签:
假设始终可以找到一种状态使得值为0, 那么两个1之间需要隔n-2个数, 两个2之间需要隔n-3个数, 两个3之间隔n-4个数。 我们发现两个三可以放到两个1之间, 同理两个5放到两个3之间....这样就构造好了。
#include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <map> #include <set> #include <string> #include <queue> #include <stack> #include <bitset> using namespace std; #define pb(x) push_back(x) #define ll long long #define mk(x, y) make_pair(x, y) #define lson l, m, rt<<1 #define mem(a) memset(a, 0, sizeof(a)) #define rson m+1, r, rt<<1|1 #define mem1(a) memset(a, -1, sizeof(a)) #define mem2(a) memset(a, 0x3f, sizeof(a)) #define rep(i, n, a) for(int i = a; i<n; i++) #define fi first #define se second typedef pair<int, int> pll; const double PI = acos(-1.0); const double eps = 1e-8; const int mod = 1e9+7; const int inf = 1061109567; const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} }; int a[1000005]; int main() { int n; cin>>n; int l = 1, r = n, cnt = 1; while(r>l) { a[l++] = cnt, a[r--] = cnt; cnt+=2; } l = n+1, r = l+n-2, cnt = 2; while(r>l) { a[l++] = cnt, a[r--] = cnt; cnt+=2; } for(int i = 1; i<=2*n; i++) { if(a[i]) printf("%d ", a[i]); else printf("%d ", n); } return 0; }
codeforces 622. Optimal Number Permutation 构造
标签:
原文地址:http://www.cnblogs.com/yohaha/p/5218456.html