This commit is contained in:
Zengtudor 2024-08-06 11:41:16 +08:00
parent a9704560e3
commit 2f49014fef
7 changed files with 223 additions and 2 deletions

2
.gitignore vendored
View File

@ -45,3 +45,5 @@ day2/U111091/fixed
day4/T435167/T435167
day4/U461920/U461920
test.txt
day4/U76034/chat
day4/U287193/chat

View File

@ -37,6 +37,10 @@ int main(){
}
```
## Day4
### [T435167 01 Sort](./day4/T435167/T435167.md)
#### 通过异色中转
# 排序
## 稳定性
>隔着老远swap一般不稳定

View File

@ -4,9 +4,22 @@
using namespace std;
#define int long long
#ifdef DEBUG
#define PRINT_VALUE(v){cout<<#v<<" :"<<v<<endl;}
#define PRINT_ARRAY(arr,size){cout<<#arr<<" [";for(int i=1;i<=size;i++){cout<<arr[i]<<(i!=size?",":"]\n");}}
#define DEBUG_PRINT(c){cout<<c<<endl;}
#endif
#ifndef DEBUG
#define PRINT_VALUE(v)
#define PRINT_ARRAY(arr,size)
#define DEBUG_PRINT(c)
#endif
const int MAX_N = 1e3+5;
int t,n;
int a[MAX_N],b[MAX_N];
vector<pair<int, int>> histories;
bool checkAllEleGoUp(){
for(int i=2;i<=n;i++){
@ -17,7 +30,36 @@ bool checkAllEleGoUp(){
return true;
}
void sort_fixed(){
for(int i=1;i<=n;i++){
int max_num=INT_MIN;
vector<int> max_dirs;
for (int j=i; j<=n; j++) {
if (max_num<a[j]) {
max_dirs.clear();
max_num=a[j];
max_dirs.push_back(j);
}
}
int swap_dir=-1;
for (int j=0; i<max_dirs.size(); i++) {
if(b[max_dirs[j]]!=b[i]){
swap_dir=max_dirs[j];
break;
}
}
if (swap_dir==-1) {
histories.clear();
return;
}else {
histories.push_back(make_pair(i, swap_dir));
}
}
}
signed main(){
cin.sync_with_stdio(false);
cin.tie(0);
cin>>t;
for(int i=1;i<=t;i++){
bool isAllBZero=true;
@ -40,6 +82,15 @@ signed main(){
cout<<-1<<endl;
continue;
}
cout<<0<<endl;
sort_fixed();
if (histories.size()==0) {
PRINT_VALUE(histories.size());
cout<<-1<<endl;
}else {
cout<<histories.size()<<endl;
for (auto v : histories) {
cout<<v.first<<" "<<v.second<<endl;
}
}
}
}

66
day4/U287193/chat.cpp Normal file
View File

@ -0,0 +1,66 @@
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
#ifdef DEBUG
#define PRINT_VALUE(v){cout<<#v<<" :"<<v<<endl;}
#define PRINT_ARRAY(arr,size){cout<<#arr<<" [";for(int i=1;i<=size;i++){cout<<arr[i]<<(i!=size?",":"]\n");}}
#define DEBUG_PRINT(c){cout<<c<<endl;}
#endif
#ifndef DEBUG
#define PRINT_VALUE(v)
#define PRINT_ARRAY(arr,size)
#define DEBUG_PRINT(c)
#endif
int main() {
int n, m;
cin >> n >> m;
vector<int> lim(n);
for (int i = 0; i < n; ++i) {
cin >> lim[i];
}
vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
dp[0][0] = 1;
vector<int> positions;
for (int i = 1; i <= n; ++i) {
if (lim[i - 1] == 0) {
positions.push_back(i);
}
}
int total_permutations = 1;
for (int i = 1; i <= positions.size(); ++i) {
total_permutations = (total_permutations * i) % MOD;
}
for (int i = 1; i <= n; ++i) {
if (lim[i - 1] != 0) {
for (int j = 0; j <= m; ++j) {
dp[i][j] = dp[i - 1][j];
}
} else {
for (int j = 0; j <= m; ++j) {
for (int k = 0; k < i; ++k) {
if (j - k >= 0) {
dp[i][j] = (dp[i][j] + dp[i - 1][j - k]) % MOD;
}
}
}
}
}
int result = 0;
for (int j = 0; j <= m; ++j) {
result = (result + dp[n][j]) % MOD;
}
result = (result * total_permutations) % MOD;
cout << result << endl;
return 0;
}

View File

@ -25,6 +25,8 @@ void set_num_times_mem(){
}
int main(){
cin.sync_with_stdio(false);
cin.tie(0);
cin>>n;
set_num_times_mem();
PRINT_ARRAY(num_times,n);

4
day4/U76034/1.in Normal file
View File

@ -0,0 +1,4 @@
3
6 3
4 2
1244 1241

92
day4/U76034/chat.cpp Normal file
View File

@ -0,0 +1,92 @@
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#define MOD 1000000007
using namespace std;
#ifdef DEBUG
#define PRINT_VALUE(v){cout<<#v<<" :"<<v<<endl;}
#define PRINT_ARRAY(arr,size){cout<<#arr<<" [";for(int i=1;i<=size;i++){cout<<arr[i]<<(i!=size?",":"]\n");}}
#endif
#ifndef DEBUG
#define PRINT_VALUE(v)
#define PRINT_ARRAY(arr,size)
#endif
typedef long long ll;
ll power(ll a, ll b, ll mod) {
ll res = 1;
while (b > 0) {
if (b % 2 == 1)
res = (res * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return res;
}
map<ll, ll> prime_factorization(ll x) {
map<ll, ll> factors;
for (ll i = 2; i * i <= x; ++i) {
while (x % i == 0) {
factors[i]++;
x /= i;
}
}
if (x > 1) {
factors[x]++;
}
return factors;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int q;
cin >> q;
vector<pair<ll, ll>> queries(q);
for (int i = 0; i < q; ++i) {
cin >> queries[i].first >> queries[i].second;
}
const int MAXN = 1e6 + 5;
vector<ll> fact(2 * MAXN), invFact(2 * MAXN);
fact[0] = 1;
for (int i = 1; i < 2 * MAXN; ++i) {
fact[i] = fact[i - 1] * i % MOD;
}
invFact[2 * MAXN - 1] = power(fact[2 * MAXN - 1], MOD - 2, MOD);
for (int i = 2 * MAXN - 2; i >= 0; --i) {
invFact[i] = invFact[i + 1] * (i + 1) % MOD;
}
auto binomial = [&](ll n, ll k) {
if (n < k) return 0LL;
return fact[n] * invFact[k] % MOD * invFact[n - k] % MOD;
};
for (auto [x, n] : queries) {
if (n == 1) {
cout << (x == 1 ? 1 : 2) << '\n';
continue;
}
map<ll, ll> factors = prime_factorization(x);
ll result = 1;
for (auto [p, e] : factors) {
result = result * binomial(2 * n + e - 1, e) % MOD;
}
cout << result << '\n';
}
return 0;
}