码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • AcWing.第121场周赛


    以下是acwing第121场比赛的abc三题

    比赛地址 : 

    竞赛 - AcWing

    A.    AcWing 5149. 简单计算 

    题目链接 : 

    5149. 简单计算 - AcWing题库

    思路 : 

    直接模拟,用floor()函数来实现下取整

    代码

    1. #include
    2. #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    3. #define endl '\n'
    4. using namespace std;
    5. typedef long long LL;
    6. int gcd(int a,int b){ return b==0 ? a : gcd(b,a%b); }
    7. int lcm(int a,int b){ if(a==0||b==0) return 0; return (a*b)/gcd(a,b); }
    8. bool is_prime(int x){if(x<2) return false;
    9. for(int i=2;i<=x/i;i++) if(x%i==0) return false; return true;}
    10. //numbers.erase(std::unique(numbers.begin(), numbers.end()), numbers.end()); // 去重操作
    11. const int N = 2e5+10;
    12. inline void solve(){
    13. int x,y,z; cin>>x>>y>>z;
    14. int ans = floor(1.0 * (z-y) / x) *x + y;
    15. cout << ans << endl;
    16. }
    17. int main()
    18. {
    19. IOS
    20. int _;
    21. cin >> _;
    22. // _ = 1;
    23. while(_ --) solve();
    24. return 0;
    25. }

    B.  5150.顶牛

    题目链接 : 

    5150. 顶牛 - AcWing题库

    思路 : 

    如果没出现a[i][j] = 1 || a[i][j] =  3,那么代表i牛是满足题目条件的;
    这样模拟即可!

    代码 : 

    1. #include
    2. #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    3. #define endl '\n'
    4. using namespace std;
    5. typedef long long LL;
    6. int gcd(int a,int b){ return b==0 ? a : gcd(b,a%b); }
    7. int lcm(int a,int b){ if(a==0||b==0) return 0; return (a*b)/gcd(a,b); }
    8. bool is_prime(int x){if(x<2) return false;
    9. for(int i=2;i<=x/i;i++) if(x%i==0) return false; return true;}
    10. //numbers.erase(std::unique(numbers.begin(), numbers.end()), numbers.end()); // 去重操作
    11. const int N = 105;
    12. int n,a[N][N];
    13. inline void solve(){
    14. int ans = 0;
    15. vector<int> res;
    16. cin >> n;
    17. for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>a[i][j];
    18. for(int i=1;i<=n;i++){
    19. bool tag = true;
    20. for(int j=1;j<=n;j++){
    21. if(a[i][j]==1 || a[i][j]==3){
    22. tag = false;
    23. break;
    24. }
    25. }
    26. if(tag){
    27. res.push_back(i);
    28. ans ++;
    29. }
    30. }
    31. cout << ans << endl;
    32. for(int num : res) cout << num << " ";
    33. return ;
    34. }
    35. int main()
    36. {
    37. IOS
    38. int _;
    39. // cin >> _;
    40. _ = 1;
    41. while(_ --) solve();
    42. return 0;
    43. }

    C.        5151.程序调用

    原题链接 : 

    5151. 程序调用 - AcWing题库

    思路 : 

    用hsah表实现模拟,否则会超时!!!

    代码 : 

    1. #include
    2. using namespace std;
    3. typedef long long LL;
    4. const int N = 1e5+144;
    5. LL n, m, k,a[N],ans;
    6. unordered_map mp;
    7. void swap(int &x,int &y){
    8. int tmp = x;
    9. x = y;
    10. y = tmp;
    11. }
    12. int main()
    13. {
    14. cin>>n>>m>>k;
    15. for(int i=1;i<=n;i++){
    16. cin>>a[i];
    17. mp[a[i]] = i;
    18. }
    19. for(int i=1;i<=m;i++){
    20. int b ; cin>>b;
    21. if(mp[b]%k==0) ans += mp[b]/k;
    22. else ans += mp[b]/k+1;
    23. int idx = mp[b];
    24. if(idx==1) continue;
    25. int beforeNum = a[idx-1];
    26. swap(a[idx-1],a[idx]);
    27. swap(mp[b],mp[beforeNum]);
    28. }
    29. cout << ans << endl;
    30. return 0;
    31. }

  • 相关阅读:
    【尘缘赠书活动:01期】Python数据挖掘——入门进阶与实用案例分析
    通达信交易系统接口实现自动交易策略的方法分享
    Codeforces Round 929 (Div. 3 ABCDEFG题) 视频讲解
    环境治理行业标识解析二级节点平台建设解决方案
    怎么做好企业短信服务呢?(文字短信XML接口示例)
    CVPR2023优秀论文 | AIGC伪造图像鉴别算法泛化性缺失问题分析
    ZFS文件系统预研资料
    java.sql.SQLSyntaxErrorException: Unknown column ‘id‘ in ‘field list‘
    Mybatis( If条件失效 )
    WIFI简介 以及SDIO总线介绍
  • 原文地址:https://blog.csdn.net/ros275229/article/details/132943455
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | 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号