传送门:Dashboard - Codeforces Round 992 (Div. 2) - Codeforces
A. Game of Division
思路:模拟
AC代码:Submission #295676347 - Codeforces
B. Paint a Strip
思路:数学 + 贪心
放置的位置一定是 1 4 10 22 48 .....
放置的位置 一定是 2 * i + 2
AC代码:Submission #295676364 - Codeforces
C. Ordered Permutations
题意:
思路:
打表找规律
打表代码:
#include<bits/stdc++.h>
using namespace std;
int n, ans;
vector<vector<int>> res;
int a[55];
int used[55];
void dfs(int d) {if (d > n) {int h = 0;for (int i = 1; i <= n; i++) {for (int j = i; j <= n; j++) {int k = 1e9;for (int t = i; t <= j; t++) {k = min(a[t], k);}h += k;}}if (h > ans) {ans = h;res.clear();}if (h == ans) {vector<int> temp(n + 1);for (int i = 1; i <= n; i++) temp[i] = a[i];res.push_back(temp);}return;}for (int i = 1; i <= n; i++) {if (!used[i]) {a[d] = i;used[i] = 1;dfs(d + 1);used[i] = 0;}}
}
int main() {for (int i = 1; i <= 10; i++){res.clear();n = i;dfs(1);cout << i << " " << res.size() << endl;for (auto e : res){for (int j = 1; j < e.size(); j++) cout << e[j] << " ";cout << endl;}cout << endl;}return 0;
}
eg : n == 5
1 在最左边的出现的次数是 8 ,2 的最左边的出现的次数 4
数字 i 出现的次数是 1 << ( n - i - 1 )
模拟
AC代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{int n , k; cin >> n >> k;// 2 的 60 次方 > 1e12 if( n <= 61 && 1ll << ( n - 1 ) < k ){puts("-1"); return;}k--;vector<int> a(n);int l = 0 , r = n;for( int i = 1 ; i < n ; i++ ){if( n - i - 1 >= 60 || 1ll << ( n - i - 1 ) > k ){a[l++] = i; // 放在最左边}else{k -= 1ll << ( n - i - 1 );a[--r] = i; // 放在最右边}}a[l] = n;for( int i = 0 ; i < n ; i++ ) cout << a[i] << " ";cout << endl;
}
signed main()
{int tt ; cin >> tt;while(tt--)solve();return 0;
}