Tower

https://www.luogu.com.cn/problem/list?keyword=icpc2022jinan&type=AT%7CB%7CCF%7CP%7CSP%7CUVA&page=1

#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#define endl "\n"
#define int long long

using namespace std;
const int N = 5005;
int n,m;
int a[N],ans[N],cha[N];
int T;

void solve()
{
    cin>>n>>m;
    int geshu=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        int x=a[i];
        while(x){
            ans[++geshu]=x;			//记录最终答案可能的值
            x/=2;
        }
    }

    int minn=1e17;
    for(int i=1;i<=geshu;i++){		//枚举所有最终答案
        int x=ans[i];
        int cnt=0;
        for(int j=1;j<=n;j++){
            cha[j]=1e10;
            if(a[j]<x)cha[j]=x-a[j];	//小于最终答案的值只能通过+1来操作
            else if(a[j]==x){
                cha[j]=0;
                continue;
            }
            else {			//大于最终答案的值先不断/2再加减
                int num=a[j],shu=0;
                while(num>x){
                    if(num>x&&(num/2)<=x){
                        cha[j]=min(shu+num-x,shu+1+(x-num/2));
                        break;
                    }
                    num/=2;shu++;
                }

            }
        }

        sort(cha+1,cha+1+n);
        for(int j=1;j<=n-m;j++)cnt+=cha[j];

        minn=min(minn,cnt);

    }

    cout<<minn<<endl;


    return;
}
signed main() {
    cin >> T;
    while(T--) {
        solve();

    }
    return 0;


}

Best Carry Player

https://www.luogu.com.cn/problem/P9679

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdlib>
#include <queue>
#define LL long long
#define endl "\n"
#define debug(x) std:: cout << "---DEBUG--- " << x << " -----DEBUG----\n"

using namespace std;
const int maxn = 3e5+5;
string s;
char sr[20]= {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
int T;
int n;
int sum[20], ans;
int t;
void solve(){
    cin >> n;
    ans = 0;
    for(int i = 1; i <= 15; i++) sum[i] = 0;
    for(int i = 1; i <= n; i++){
        cin >> t;
        for(int j = 1; t != 0; j++){
            sum[j] += t % 10;
            t/=10;
        }
    }
    for(int j = 1; j <= 15; j++){
        ans += sum[j] / 10;
        sum[j+1] += sum[j] / 10;
    }
    cout << ans << endl;
}
int main() {
    cin >> T;
    while(T--){
        solve();
    }
    return 0;
}

Identical Parity

https://www.luogu.com.cn/problem/P9671

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdlib>
#include <queue>
#define LL long long
#define endl "\n"
#define debug(x) std:: cout << "---DEBUG--- " << x << " -----DEBUG----\n"

using namespace std;
const int maxn = 3e5+5;
string s;
char sr[20]= {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
int T;
int n;
int k;
bool solve() {
    cin >> n >> k;
    if(k % 2 == 0) return true;
    int num1 = (n + 1) / 2 - (k + 1) / 2 * (n / k);
    int num2 = n / 2 - k / 2 * (n / k);
    if (num1 >= 0 and num1 <= (k + 1) / 2 and num2 >= 0 and num2 <= k / 2) return true; //最后的一块可以分配好么
    //if(num1 - num2 == 1 || num1 - num2 == 0) return true;
    else return false;
}
int main() {
    cin >> T;
    while(T--) {
        if(solve()){cout << "yes" << endl;}
        else {cout << "no" << endl;}
    }
    return 0;
}