2022“杭电杯”中国大学生算法设计超级联赛(8)题解报告

本文精选了五道算法竞赛题目并提供了详细的题解,包括最小生成树、区间查询、坐标枚举等技巧,通过这些题解帮助读者理解并掌握算法竞赛中的常见解题思路。

Problem D. Quel’Thalas

题解:

手玩一下就会发现答案是就是2n。

代码:

#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<cstring>
#include<cmath>
#define pi acos(-1)
#define int long long
#define double long double
#define INF 0x3f3f3f3f3f3f3f3f
using namespace std;

const int N = 1e6 + 10;

int n;

void solve()
{
    cin >> n;
    cout << 2 * n << '\n';
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
}

Problem A. Theramore

题解:

对于奇偶性相同的位置可以任意交换位置,所以对于奇偶位置单独处理即可。

代码:

#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<cstring>
#include<cmath>
#define pi acos(-1)
#define int long long
#define double long double
#define INF 0x3f3f3f3f3f3f3f3f
using namespace std;

const int N = 1e6 + 10;

string s;
char a[N], b[N];

void solve()
{
    cin >> s;
    int len = s.length();
    int la = 0, lb = 0;
    for(int i = 0; i < len; i++){
        if(i % 2) b[++lb] = s[i];
        else a[++la] = s[i];
    }
    sort(a + 1, a + 1 + la);
    sort(b + 1, b + 1 + lb);
    for(int i = 1; i <= len / 2; i ++) cout << a[i] << b[i];
    if(len % 2) cout << b[lb] << '\n';
    else cout << '\n';
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t;
    cin 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值