首页 > 其他分享 >AtCoder abc336 A-D题代码

AtCoder abc336 A-D题代码

时间:2024-01-27 13:22:21浏览次数:22  
标签:AtCoder cout int 代码 namespace long abc336 ans main

A题:

#include <bits/stdc++.h>

using namespace std;

int main () {
    int n;
    cin >> n;
    cout << "L" << string(n, 'o') << "ng" << endl;
    return 0;
}

B题:

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;
int a[N];

int main () {
    int n;
    cin >> n;
    int i = 0;
    while (n != 0) {
        ++i;
        a[i] = n % 2;
        n /= 2;
    }
    //for (int j = i; j >= 1; j--) cout << a[j];
    int ans = 0;
    for (int j = 1; j <= i; j++) {
        if (a[j] != 0) {
            break;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}

C题:

#include <bits/stdc++.h>

using namespace std;

const int N = 1e7 + 10;
long long int a[N];

int main () {
    long long int n, m = 1;
    scanf ("%lld", &n);
    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }
    long long int i = 0;
    n -= 1;
    while (n != 0) {
        ++i;
        a[i] = n % 5 * 2;
        n /= 5;
    }
    for (long long int j = i; j >= 1; j--) {
        cout << a[j];
    }
    cout << endl;
    return 0;
}

D题:

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;
long long int a[N];
long long int b[N], c[N]; 
long long int ans[N];

int main () {
    long long int n;
    cin >> n;
    for (long long int i = 1; i <= n; i++) {
        cin >>a[i];
    }
    for (long long int i = 1; i <= n; i++) {
        //if (i == 1) a[i - 1] = 1;
        b[i] = min (a[i], b[i - 1] + 1);
    }
    for (long long int i = n; i >= 1; i--) {
        //if (i == n) a[i + 1] = 1;
        c[i] = min (a[i], c[i + 1] + 1);
        ans[i] = min (c[i], b[i]);
    }
    sort (ans + 1, ans + 1 + n);
    cout << ans[n];
    return 0;
}

 

标签:AtCoder,cout,int,代码,namespace,long,abc336,ans,main
From: https://www.cnblogs.com/thjblogs/p/17991338

相关文章

  • 类,对象--示例代码
    #include<iostream>usingnamespacestd;classBox{ private: doublelength; doublewidth; public: voidsetLength(doublelength); voidsetWidth(doublewidth); doublegetLength(); doublegetWidth(); doublegetArea(); };voidBox::setLength......
  • 类 代码示范
    #include<iostream>usingnamespacestd;classBox{ private: doublelength; doublewidth; public: voidsetLength(doublelength); voidsetWidth(doublewidth); doublegetLength(); doublegetWidth(); doublegetArea();};voidBox::setLen......
  • 梳理拯救烂怂代码?我是这么做的
    分享是最有效的学习方式。博客:https://blog.ktdaddy.com/故事这几天的小猫心情还不错,修完了"幂等事件的bug",填完了"缓存击穿的坑",前两天组长交代给他的“整理一份系统现状报告”任务也算是有了思路,阴霾终于散去。好像一切都朝着好的方向发展了。是的,也该过去了,毕竟这些事情......
  • 代码随想录算法训练营第三天| 203.移除链表元素,707.设计链表 ,206.反转链表
    203.移除链表元素给你一个链表的头节点 head 和一个整数 val ,请你删除链表中所有满足 Node.val==val 的节点,并返回 新的头节点 。题目链接:203.移除链表元素-力扣(LeetCode)注意c++中NULL和nullptr的区别。应该用nullptr来表示空指针。/***Definitionforsingly......
  • iMessage群发软件开发源代码段分享
    随着科技的飞速发展,人们对于信息传递的需求越来越高,而iMessage作为苹果公司推出的即时通讯工具,因其便捷、安全和高效而备受用户喜爱。然而,对于一些开发者和企业来说,如何实现iMessage群发功能成为了他们面临的一大难题,为此,本文将分享一些iMessage群发软件开发的源代码段,帮助大家快速......
  • 【C++】前置声明导致的代码含义改变
    真的有这么离谱的事哈哈哈哈。//F.hstructF{};structS:F{};//User.h#include<iostream>structF;structS;structUser{voidf(F*){std::cout<<"F"<<std::endl;}voidf(void*){std::cout<<"void"<......
  • python--pyQt 基础框架代码 pyside6
    importsysfromPySide6importQtWidgets,QtCore,QtGuifromPySide6.QtCoreimportQt,QRectfromPySide6.QtGuiimportQColor,QEnterEventfromPySide6.QtWidgetsimportQApplication,QDialog,QMainWindow,QGraphicsDropShadowEffectimportyiqi_uiclassMain......
  • 使用Visual Studio调试微软源代码
    思维导航前言VisualStudio更多实用技巧取消选中启用仅我的代码选中启用源链接支持选中启用符号服务器启用在模块加载时取消JIT优化(仅限托管)[可选]启用VisualStudio调试源码DotNetGuide技术社区交流群前言在我们日常开发过程中常常会使用到很多其他封装好的第......
  • 15 个写代码的好习惯(可以减少 80% 非业务的 bug)
    引言作为一名刚入行的程序员,平时在编写代码时最好养成一些好习惯,这样可以避免或减少各种非业务的bug,从而提高开发效率,这里总结了常见的15个平时写代码的好习惯,希望对你有所帮助。1.修改完代码,记得自测一下「改完代码,自测一下」是每位程序员必备的基本素养。尤其不要抱有这......
  • Starrocks扩展FileSystem代码分析
    Starrocks扩展FileSystem代码分析Starrocks支持使用FILES()算子对接文件系统例如可以使用insertintofiles("path"="hdfs://xxx.xx.xxx.xx:9000/unload/data1","format"="parquet","compression"="lz4")select*fromsales_reco......