由于最近这三天的数学建模,让我这个精力本来就不多的AI手更加力竭了,没注意到昨晚的cf,所以今天来补题了。
比赛连接:比赛传送门
A题:
You are doing a research paper on the famous Collatz Conjecture. In your experiment, you start off with an integer xxx, and you do the following procedure kkk times:
- If xxx is even, divide xxx by 222.
- Otherwise, set xxx to 3⋅x+13\cdot x+13⋅x+1.
For example, starting off with 212121 and doing the procedure 555 times, you get 21→64→32→16→8→421\rightarrow64\rightarrow32\rightarrow16\rightarrow8\rightarrow421→64→32→16→8→4.
After all kkk iterations, you are left with the final value of xxx. Unfortunately, you forgot the initial value. Please output any possible initial value of xxx.
Input
Each test contains multiple test cases. The first line contains the number of test cases ttt (1≤t≤4001 \le t \le 4001≤t≤400). The description of the test cases follows.
The first line of each test case contains two integers kkk and xxx (1≤k,x≤201 \leq k,x \leq 201≤k,x≤20).
Output
For each test case, print any possible initial value on a new line. It can be shown that the answer always exists.
Note
In the first test case, since 111 is odd, performing the procedure k=1k=1k=1 times results in 1⋅3+1=41\cdot3+1=41⋅3+1=4, so 111 is a valid output.
In the second test case, since 101010 is even, performing the procedure k=1k=1k=1 times results in 102=5\frac{10}{2}=5210=5, so 101010 is a valid output.
The third test case is explained in the statement.
通过观察不难发现,两种操作都是变为了偶数,所以一直在原来的基础上乘2即可(永远都只用操作一即可)。
// Problem: A. Collatz Conjecture
// Contest: Codeforces - Codeforces Round 1047 (Div. 3)
// URL: https://codeforces.com/contest/2137/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pii pair<int,int>
#define fi first
#define se second
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define lbt(x) ((x) & (-x)) const int INF = 0x3f3f3f3f;
const int inf = 1e18; void solve()
{int n,k;cin>>k>>n;int an = n;for(int i=1;i<=k;i++) an *= 2LL;cout<<an<<endl;
// cout<<fixed<<setprecision(x)<< ;
}signed main()// Don't forget pre_handle!
{IOSint T=1;cin>>T;while(T--) solve(); return 0;
}
B题
You are given a permutation∗^{\text{∗}}∗ ppp of size nnn.
Your task is to find a permutation qqq of size nnn such that GCD\operatorname{GCD}GCD†^{\text{†}}†(pi+qi,pi+1+qi+1)≥3(p_i+q_i, p_{i+1}+q_{i+1}) \geq 3(pi+qi,pi+1+qi+1)≥3 for all KaTeX parse error: Expected 'EOF', got '&' at position 9: 1 \leq i&̲lt;n. In other words, the greatest common divisor of the sum of any two adjacent positions should be at least 333.
It can be shown that this is always possible.
∗^{\text{∗}}∗A permutation of length mmm is an array consisting of mmm distinct integers from 111 to mmm in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2][1,2,2] is not a permutation (222 appears twice in the array), and [1,3,4][1,3,4][1,3,4] is also not a permutation (m=3m=3m=3 but there is 444 in the array).
†^{\text{†}}†gcd(x,y)\gcd(x, y)gcd(x,y) denotes the greatest common divisor (GCD) of integers xxx and yyy.
Input
Each test contains multiple test cases. The first line contains the number of test cases ttt (1≤t≤1041 \le t \le 10^41≤t≤104). The description of the test cases follows.
The first line of each test case contains an integer nnn (2≤n≤2⋅1052 \leq n \leq 2\cdot 10^52≤n≤2⋅105).
The second line contains nnn integers p1,p2,…,pnp_1,p_2,\ldots,p_np1,p2,…,pn (1≤pi≤n1 \leq p_i \leq n1≤pi≤n).
It is guaranteed that the given array forms a permutation.
It is guaranteed that the sum of nnn over all test cases does not exceed 2⋅1052\cdot 10^52⋅105.
Output
For each test case, output the permutation qqq on a new line. If there are multiple possible answers, you may output any.
Note
In the first test case, GCD(1+2,3+3)=3≥3\operatorname{GCD}(1+2,3+3)=3\geq 3GCD(1+2,3+3)=3≥3 and GCD(3+3,2+1)=3≥3\operatorname{GCD}(3+3,2+1)=3\geq3GCD(3+3,2+1)=3≥3, so the output is correct.
这道题也很好想,最大公约数,又因为是排列,所以我们肯定不难想到用最大的和去和每个元素进行配对,这样所有的两个位置上两个排列中所对应的数相加的和都相同了,那么这个时候就是满足条件的排列了。
// Problem: B. Fun Permutation
// Contest: Codeforces - Codeforces Round 1047 (Div. 3)
// URL: https://codeforces.com/contest/2137/problem/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pii pair<int,int>
#define fi first
#define se second
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define lbt(x) ((x) & (-x)) const int INF = 0x3f3f3f3f;
const int inf = 1e18; void solve()
{int n;cin>>n;vector<int> a(n+1);for(int i=1;i<=n;i++) cin>>a[i];int sum = n + 1;for(int i=1;i<=n;i++) cout<<sum - a[i]<<' ';cout<<endl;
// cout<<fixed<<setprecision(x)<< ;
}signed main()// Don't forget pre_handle!
{IOSint T=1;cin>>T;while(T--) solve(); return 0;
}
C题
You are given two integers aaa and bbb. You are to perform the following procedure:
First, you choose an integer kkk such that bbb is divisible by kkk. Then, you simultaneously multiply aaa by kkk and divide bbb by kkk.
Find the greatest possible even value of a+ba+ba+b. If it is impossible to make a+ba+ba+b even, output −1-1−1 instead.
Input
Each test contains multiple test cases. The first line contains the number of test cases ttt (1≤t≤1041 \le t \le 10^41≤t≤104). The description of the test cases follows.
The first line of each test case contains two integers aaa and bbb (1≤a,b≤a⋅b≤1018)1 \leq a,b \leq a\cdot b \leq 10^{18})1≤a,b≤a⋅b≤1018).
Output
For each test case, output the maximum even value of a+ba+ba+b on a new line.
Note
In the first test case, it can be shown it is impossible for a+ba+ba+b to be even.
In the second test case, the optimal kkk is 222. The sum is 2+4=62+4=62+4=6.
分情况讨论即可
// Problem: C. Maximum Even Sum
// Contest: Codeforces - Codeforces Round 1047 (Div. 3)
// URL: https://codeforces.com/contest/2137/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pii pair<int,int>
#define fi first
#define se second
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define lbt(x) ((x) & (-x)) const int INF = 0x3f3f3f3f;
const int inf = 1e18; void solve()
{int a,b;cin>>a>>b;if((a * b) & 1) {cout<<a * b + 1<<endl;return ;}int ans = -1;if(b & 1){cout<<ans<<endl;return ;}if((a * (b / 2LL) + 2LL) & 1){cout<<ans<<endl;return ;}// if(a & 1LL)// {cout<<a * (b / 2LL) + 2LL<<endl;return ;// }// if(a % 2 == 0)// {// cout<<a * b// }
// cout<<fixed<<setprecision(x)<< ;
}signed main()// Don't forget pre_handle!
{IOSint T=1;cin>>T;while(T--) solve(); return 0;
}
D题
Given an array aaa, let f(x)f(x)f(x) be the number of occurrences of xxx in the array aaa. For example, when a=[1,2,3,1,4]a=[1,2,3,1,4]a=[1,2,3,1,4], then f(1)=2f(1)=2f(1)=2 and f(3)=1f(3)=1f(3)=1.
You have an array bbb of size nnn. Please determine if there is an array aaa of size nnn such that f(ai)=bif(a_i)=b_if(ai)=bi for all 1≤i≤n1 \leq i \leq n1≤i≤n. If there is one, construct it.
Input
Each test contains multiple test cases. The first line contains the number of test cases ttt (1≤t≤1041 \le t \le 10^41≤t≤104). The description of the test cases follows.
The first line of each test case contains an integer nnn (1≤n≤2⋅1051 \leq n \leq 2\cdot 10^51≤n≤2⋅105).
The second line contains nnn integers b1,b2,…,bnb_1,b_2,\ldots,b_nb1,b2,…,bn (1≤bi≤n1 \leq b_i \leq n1≤bi≤n).
It is guaranteed that the sum of nnn over all test cases does not exceed 2⋅1052\cdot 10^52⋅105.
Output
For each test case, output −1-1−1 if there is no valid array aaa.
Otherwise, print the array aaa of nnn integers on a new line. The elements should satisfy 1≤ai≤n1 \leq a_i \leq n1≤ai≤n.
Note
In the first test case, it can be shown that no array matches the requirement.
In the second test case, 444, 555, 666 appear 1,2,31,2,31,2,3 times respectively. Thus, the output array is correct as f(4),f(5),f(5),f(6),f(6),f(6)f(4),f(5),f(5),f(6),f(6),f(6)f(4),f(5),f(5),f(6),f(6),f(6) are 1,2,2,3,3,31,2,2,3,3,31,2,2,3,3,3 respectively.
这道题用map嵌套pair可以省去很多步骤,思路也比较清楚
// Problem: D. Replace with Occurrences
// Contest: Codeforces - Codeforces Round 1047 (Div. 3)
// URL: https://codeforces.com/contest/2137/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pii pair<int,int>
#define fi first
#define se second
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define lbt(x) ((x) & (-x)) const int INF = 0x3f3f3f3f;
const int inf = 1e18; void solve()
{int n;cin>>n;vector<int> a(n+1);for(int i=1;i<=n;i++) cin>>a[i];map<int,pii> mp;for(int i=1;i<=n;i++) mp[a[i]].fi ++,mp[a[i]].se = 0;int num = 0;for(auto &i : mp) num += i.se.fi;if(num != n){cout<<"-1"<<endl;return ;}for(auto &i : mp){int t1 = i.fi,t2 = i.se.fi;if(t2 % t1){cout<<"-1"<<endl;return ;}}int index = 0LL;map<int,int> cnt;map<int,bool> v;for(int i=1;i<=n;i++){if(!v[a[i]]) mp[a[i]].se = ++index;if(cnt[a[i]] == a[i]){cnt[a[i]] = 0;mp[a[i]].se = ++index;}cnt[a[i]] ++;v[a[i]] = true;cout<<mp[a[i]].se<<' ';}// for(int i=1;i<=n;i++) cout<<mp[a[i]].se<<' ';cout<<endl;
// cout<<fixed<<setprecision(x)<< ;
}signed main()// Don't forget pre_handle!
{IOSint T=1;cin>>T;while(T--) solve(); return 0;
}