当前位置: 首页 > news >正文

【CF】Day26——Teza Round 1 (Codeforces Round 1015, Div. 1 + Div. 2) CD

C. You Soared Afar With Grace

题目:

思路:

很有意思的模拟题,代码细节需注意

因为题目没要求我们最小步骤什么的,同时n也比较小,所以按照题意模拟即可,但是注意细节,比如数的位置,奇偶性,特殊情况等

代码:

#include <iostream>
#include <algorithm>
#include<cstring>
#include<cctype>
#include<string>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <memory>
using namespace std;
#define int long long
#define yes cout << "YES\n"
#define no cout << "NO\n"

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n+1),b(n+1);
    vector<int> bpos(n+1,0);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    int flag = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> b[i];
        flag |= (b[i] != a[n+1 - i]);
        bpos[b[i]] = i;
    }
    if (!flag)
    {
        cout << "0\n";
        return;
    }
    int num = 0;
    vector<pair<int, int>> ans;
    for (int i = 1; i <= n; i++)
    {
        if (a[bpos[a[i]]] != b[i])
        {
            cout << "-1\n";
            return;
        }
        if (a[i] == b[i])
        {
            if (n % 2 == 0 || num)
            {
                cout << "-1\n";
                return;
            }
            num = i;
        }
    }
    auto change = [&](int x,int y) {
        if (x == y)
        {
            return;
        }
        ans.push_back({ x,y });
        swap(a[x], a[y]);
        swap(b[x], b[y]);
        swap(bpos[b[x]], bpos[b[y]]);
        };
    if (num)
    {
        change(num, (n + 1) / 2);
    }
    for (int i = 1; i <= n / 2; i++)
    {
        change(bpos[a[i]], n + 1 - i);
    }
    cout << ans.size() << endl;
    for (auto x : ans)
        wcout << x.first << " " << x.second << endl;
}

signed main()
{
    cin.tie(0)->sync_with_stdio(false);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

D. Arcology On Permafrost

题目:

思路:

需要一点观察的构造题

 我们最优的解法肯定是构造出一个类似与于 0 1 2 ... d 0 1 2 ... d 0 1 ... 这样的序列,其中任意一个数字都要出现 m + 1 次,这样才能保证最后能剩下这个数,同时相同的数一定要间隔 k ,这样才能保证不会一次删除两个的情况

所以这个 d 的最大值就是 n / (m + 1) - 1 (要包含0),间隔就是 max(d,k)

代码还是很好写的

代码:

#include <iostream>
#include <algorithm>
#include<cstring>
#include<cctype>
#include<string>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <memory>
using namespace std;
#define int long long
#define yes cout << "YES\n"
#define no cout << "NO\n"

void solve()
{
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> ans(n);
    int d = n / (m + 1);
    for (int i = 0; i < d; ++i) 
    {
        for (int j = i; j < n; j += max(k, d))
        {
            ans[j] = i;
        }
    }
    for (int i = 0; i < n; ++i) 
    {
        cout << ans[i] << " ";
    }
    cout << endl;
}

signed main()
{
    cin.tie(0)->sync_with_stdio(false);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

相关文章:

  • UE5学习笔记 FPS游戏制作44 统一UI大小 sizeBox
  • 关于OEC/OEC-turbo刷机问题的一些解决方法(2)——可能是终极解决方法了
  • day24学习Pandas库
  • k8s核心资源对象一(入门到精通)
  • 3D激光轮廓仪知识整理(待补充)
  • browser-use开源程序使 AI 代理可以访问网站,自动完成特定的指定任务,告诉您的计算机该做什么,它就会完成它。
  • 大模型论文:Improving Language Understanding by Generative Pre-Training
  • windterm终端软件使用
  • React-Markdown 组件底层实现原理详解
  • 服务异常挂掉问题:java invoked oom-killer
  • 数字三角形(dfs+动态规划)通过率未达100%
  • 第三次PID状态机
  • 评价区动态加载是怎么实现的?
  • 【AI学习】初步了解Gradio
  • Motionface MFvector照片一键转矢量工具使用教程
  • LeetCode算法题(Go语言实现)_34
  • 排序扩展-文件递归排序(外排序)
  • [ERROR] Some problems were encountered while processing the POMs
  • 鸿蒙开发_ARKTS快速入门_语法说明_组件声明_组件手册查看---纯血鸿蒙HarmonyOS5.0工作笔记010
  • 1631. 最小体力消耗路径
  • 上海蝉联全国中小企业发展环境评估综合排名第一
  • 从《缶翁的世界》开始,看吴昌硕等湖州籍书画家对海派的影响
  • 竞彩湃|英超欧冠悬念持续,纽卡斯尔诺丁汉能否拿分?
  • 纽约市长称墨海军帆船撞桥已致2人死亡,撞桥前船只疑似失去动力
  • 三方合作会否受政局变化影响?“中日韩+”智库合作论坛在沪举行
  • 特朗普:将于19日分别与普京和泽连斯基通话