码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • CodeTON Round 3 (Div. 1 + Div. 2, Rated, Prizes!) A. Indirect Sort 解题报告


    原题链接:

    Problem - A - Codeforces (Unofficial mirror by Menci)

    题目描述:

    You are given a permutation a1,a2,…,ana1,a2,…,an of size nn, where each integer from 11 to nn appears exactly once.

    You can do the following operation any number of times (possibly, zero):

    • Choose any three indices i,j,ki,j,k (1≤i
    • If ai>akai>ak, replace aiai with ai+ajai+aj. Otherwise, swap ajaj and akak.

    Determine whether you can make the array aa sorted in non-descending order.

    Input

    Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤50001≤t≤5000) — the number of test cases. The description of test cases follows.

    The first line of each test case contains a single integer nn (3≤n≤103≤n≤10) — the length of the array aa.

    The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤n1≤ai≤n, ai≠ajai≠aj if i≠ji≠j) — the elements of the array aa.

    Output

    For each test case, output "Yes" (without quotes) if the array can be sorted in non-descending order, and "No" (without quotes) otherwise.

    You can output "Yes" and "No" in any case (for example, strings "YES", "yEs" and "yes" will be recognized as a positive response).

    解题思路:

    要使用题目要求的方式进行排序的话,数组第一位必须是1,否则无解。

    只要数组第一位是1,总能用这个1把整个数组都排好。

    代码(CPP):

    1. #include
    2. using namespace std;
    3. #define endl '\n'
    4. typedef long long ll;
    5. typedef unsigned long long ull;
    6. const int maxn = 1e3 + 10;
    7. const int INF = 0x3fffffff;
    8. /*
    9. 要使用题目要求的方式进行排序的话,数组第一位必须是1,否则无解。
    10. 只要数组第一位是1,总能用这个1把整个数组都排好。
    11. */
    12. int main()
    13. {
    14. ios::sync_with_stdio(false);
    15. cin.tie(0);
    16. cout.tie(0);
    17. cout << fixed;
    18. cout.precision(18);
    19. int t;
    20. cin >> t;
    21. while(t--)
    22. {
    23. int n;
    24. cin >> n;
    25. int first;
    26. cin >> first;
    27. for (int i = 2, x; i <= n; i++)
    28. {
    29. cin >> x;
    30. }
    31. if(first == 1)
    32. cout << "YES\n";
    33. else
    34. cout << "NO\n";
    35. }
    36. return 0;
    37. }

  • 相关阅读:
    构建Docker基础镜像(ubuntu20.04+python3.9.10+pytorch-gpu-cuda11.8)
    【QT+QGIS跨平台编译】056:【pdal_lepcc+Qt跨平台编译】(一套代码、一套框架,跨平台编译)
    orc文件的读写及整合hive
    光环云入选“北京市算力互联互通试点参与企业”!
    考研英语作文主题词
    小程序如何设置首选配送公司
    香港金融科技周VERTU CSO Sophie谈Web3.0的下一个风口 手机虚拟货币移动支付
    [设计模式] 浅谈SOLID设计原则
    springboot+学校运动会信息管理 毕业设计-附源码231058
    react ant design Upload 多文件上传 beforeUpload 会调用很多次,怎么只获取一次
  • 原文地址:https://blog.csdn.net/qq_45554473/article/details/127872059
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号