codeforces 622. Optimal Number Permutation 构造
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codeforces 622. Optimal Number Permutation 构造相关的知识,希望对你有一定的参考价值。
假设始终可以找到一种状态使得值为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 构造的主要内容,如果未能解决你的问题,请参考以下文章
HZNU 2019 Summer training 6 -CodeForces - 622
Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version)(单调栈,递推)
[Codeforces Round #622 (Div. 2)] - C2. Skyscrapers (hard version) (单调栈)
Codeforces Round #622 (Div. 2)C2
Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) D2. Optimal Subsequences