首页 > 其他分享 >第 8 场 小白入门赛

第 8 场 小白入门赛

时间:2024-03-23 21:55:39浏览次数:12  
标签:入门 int ll long 小白 pair using define

第 8 场 小白入门赛

第一题:

解题思路:

乘一下。

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
#define fi first
#define se second
using piii = pair<ll, pair<ll, ll>>;
const ll inf = 1ll << 60;
using ull = unsigned long long;
// using i128 = __int128_t;
const int N = 210 + 10;

void solve()
{
    int cur = 2024;
    cur *= 2.5;
    cout << (int)cur << endl;
}

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

第二题:

解题思路:

自定义排序:比较\(a + b\)和\(b + a\)的字符串大小,按升序排序。

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
#define fi first
#define se second
using piii = pair<ll, pair<ll, ll>>;
const ll inf = 1ll << 60;
using ull = unsigned long long;
// using i128 = __int128_t;
const int N = 210 + 10;

bool cmp(string a, string b)
{
    string t1 = a + b;
    string t2 = b + a;
    return t1 < t2;
}

void solve()
{
    int n;
    cin >> n;
    vector<string> a;
    for (int i = 1; i <= n; i++)
    {
        string s;
        cin >> s;
        a.emplace_back(s);
    }
    sort(a.begin(), a.end(), cmp);
    for (auto s : a)
    {
        cout << s;
    }
    cout << endl;
}

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

第三题:

正确解题思路:

模\(10\)就是求最后个位数是多少,对于这点,我们发现只要考虑\(0\sim9\)的高次幂的规律即可。打一下表能发现周期性。

赛时解法:

快速幂拆着做。

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
#define fi first
#define se second
using piii = pair<ll, pair<ll, ll>>;
const ll inf = 1ll << 60;
using ull = unsigned long long;
// using i128 = __int128_t;
const int N = 210 + 10;

ll qmi(ll a, ll b)
{
    ll res = 1;
    while (b)
    {
        if (b & 1)
        {
            res = res * a % 10;
        }
        a = a * a % 10;
        b >>= 1;
    }
    return res;
}

void solve()
{
    ll x;
    cin >> x;
    string p;
    cin >> p;
    reverse(p.begin(), p.end());
    ll a = x;
    ll ans = 1;
    for (auto c : p)
    {
        int b = c - '0';
        if (b > 0)
        {
            ans = ans * qmi(a, b) % 10;
        }
        a = qmi(a, 10);
    }
    cout << ans << endl;
}

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

第四题:

解题思路:

递推。

\(a_1 = 0\)和\(a_1 = 2\)时序列唯一。

对于\(a_1 = 1\),对\(x_1 = 1和x_2 = 1\)分类讨论。

注意:判掉\(x_i\)不为\(0或1\)的解法。

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
#define fi first
#define se second
using piii = pair<ll, pair<ll, ll>>;
const ll inf = 1ll << 60;
using ull = unsigned long long;
// using i128 = __int128_t;
const int N = 210 + 10;

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n + 1), x(n + 1, 0);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    if (a[1] == 0)
    {
        for (int i = 3; i <= n; i++)
        {
            x[i] = a[i - 1] - (x[i - 1] + x[i - 2]);
        }
    }
    else if (a[1] == 1)
    {
        x[2] = 1;
        bool f = true;
        for (int i = 3; i <= n; i++)
        {
            x[i] = a[i - 1] - (x[i - 1] + x[i - 2]);
            if (x[i] < 0 || x[i] > 1)
            {
                f = false;
            }
        }
        if (x[n - 1] + x[n] != a[n] || !f)
        {
            x[1] = 1;
            x[2] = 0;
            for (int i = 3; i <= n; i++)
            {
                x[i] = a[i - 1] - (x[i - 1] + x[i - 2]);
            }
        }
    }
    else if (a[1] == 2)
    {
        x[1] = 1;
        x[2] = 1;
        for (int i = 3; i <= n; i++)
        {
            x[i] = a[i - 1] - (x[i - 1] + x[i - 2]);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        cout << x[i] << " \n"[i == n];
    }
}

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

第五题:

解题思路:

对于\(n = 2和n = 3\)的情况特殊讨论。所有元素都要变得相同。

整个序列只要按升序排序,头两个数字和尾两个数字相同即合法。

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
#define fi first
#define se second
using piii = pair<ll, pair<ll, ll>>;
const ll inf = 1ll << 60;
using ull = unsigned long long;
// using i128 = __int128_t;
const int N = 210 + 10;

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n + 1), cnt(110, 0);
    int mx = -1;
    int sx = -1;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        cnt[a[i]]++;
    }
    for (int i = 1; i <= n; i++)
    {
        if (cnt[i] == 0)
        {
            continue;
        }
        if (cnt[i] > mx)
        {
            sx = mx;
            mx = cnt[i];
        }
        else if (cnt[i] == mx)
        {
            sx = mx;
        }
        else if (cnt[i] > sx)
        {
            sx = cnt[i];
        }
    }
    sort(a.begin() + 1, a.end());
    if (n & 1)
    {
        if (n == 3)
        {
            cout << n - mx << "\n";
        }
        else
        {
            if (a[n - 1] != a[n] && a[1] != a[2])
            {
                if (a[n - 1] == a[n - 2] || a[2] == a[3])
                {
                    cout << 1 << "\n";
                }
                else
                {
                    cout << 2 << "\n";
                }
            }
            else if (a[n - 1] == a[n] && a[1] == a[2])
            {
                cout << 0 << "\n";
            }
            else
            {
                cout << 1 << "\n";
            }
        }
    }
    else
    {
        if (n == 2)
        {
            cout << (a[1] != a[2]) << "\n";
        }
        else
        {
            if (a[n - 1] != a[n] && a[1] != a[2])
            {
                if (a[n - 1] == a[n - 2] || a[2] == a[3])
                {
                    cout << 1 << "\n";
                }
                else
                {
                    cout << 2 << "\n";
                }
            }
            else if (a[n - 1] == a[n] && a[1] == a[2])
            {
                cout << 0 << "\n";
            }
            else
            {
                cout << 1 << "\n";
            }
        }
    }
}

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

第六题:

解题思路:

可达的最小值到最大值之间的所有数都一定可以得到。

只要\(x\)在可达的最大值和最小值之间,那么就是可以恰好得到的。

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
#define fi first
#define se second
using piii = pair<ll, pair<ll, ll>>;
const ll inf = 1ll << 60;
using ull = unsigned long long;
// using i128 = __int128_t;
const int N = 210 + 10;
void solve()
{
    int n, x;
    cin >> n >> x;
    vector<int> a(n + 2);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    vector<vector<int>> dp(n + 2, vector<int>(2));
    dp[1][0] = dp[0][0] + a[1];
    dp[1][1] = dp[0][1] + a[1];
    for (int i = 2; i <= n + 1; i++)
    {
        dp[i][0] = min(dp[i - 1][0], dp[i - 2][0]) + a[i];
    }
    for (int i = 2; i <= n + 1; i++)
    {
        dp[i][1] = max(dp[i - 1][1], dp[i - 2][1]) + a[i];
    }
    if (dp[n + 1][0] <= x && x <= dp[n + 1][1])
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
}

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

标签:入门,int,ll,long,小白,pair,using,define
From: https://www.cnblogs.com/value0/p/18091749

相关文章

  • 测试入门入门入门
    一、认识测试主要分为五个问题:1.软件测试的定义使用技术手段验证软件是否满足使用需求。2.7种测试分类的区别测试阶段:单元测试,集成测试,系统测试,验收测试。代码可见性:黑盒,灰盒,白盒。3.质量模型的重点5项功能性:功能数目,功能完成度。性能:可同时在线人数等。兼容性:平台,系......
  • 03-SparkSQL入门
    0SharkSpark的一个组件,用于大规模数据分析的SQL查询引擎。Shark提供了一种基于SQL的交互式查询方式,可以让用户轻松地对大规模数据集进行查询和分析。Shark基于Hive项目,使用Hive的元数据存储和查询语法,并基于Hive进行了性能优化和扩展。0.1设计灵感来自Google的......
  • Netty入门程序
    本章使用Netty开发一个入门程序,使用ServerBootstrap开发时间服务TimeServer,使用Bootstrap开发客户端TimeClient请求TimeServer获取时间。 开发TimeServer之前,先回顾一下使用NIO进行服务端开发的步骤。(1)创建ServerSocketChannel,配置它为非阻塞模式;(2)绑定监听,配置TCP参数,例......
  • python小白学习笔记Mac版本
    和win系统的不同之处python的cmd验证在win系统中,只需要输入python就可以得到相关python的版本信息但是在mac系统中,需要输入python3.12(3.12是具体版本的号码)只输入python和pip也显示找不到相关文件(已经成功的安装前提下)只有输入第三行代码python3.12才会显示pyth......
  • Java基础入门:数据、控制与异常全解析
    Java基础知识回顾:数据类型、控制结构、异常处理Java作为一门面向对象的编程语言,具有丰富的数据类型、灵活的控制结构和强大的异常处理机制。本篇文章将带大家回顾Java的基础知识,包括数据类型、控制结构和异常处理,希望对大家有所帮助。1.数据类型Java中的数据类型分为基......
  • cass-2-入门命令
    常识快捷键F3开启参照点捕捉,只能选择一些交点、锤点等等的参照点F9开启栅格网捕捉,顶点只能是栅格交点F8开启正交,只能横平竖直的划线选择操作从左往右是,全选才选中从右往左是,碰到就选中按住鼠标就是异形选择不按住鼠标就是方框选择伴生文件问题生成dwg文件的同时也......
  • 摸爬滚打半年,我是如何从小白进阶到渗透测试工程师
    前言工作也好几年了,在这摸爬滚打中,遇到了服务器被黑,网站被人DDOS攻击,数据库被篡改等等。服务器也不是你说不让人上就不让人上的,所以IT安全这个话题还是比较沉重的,涉及的东西很多,只有你了解得更多,你才会知道你所了解的安全其实是那么少。【点此开始渗透学习】梦想的开始......
  • Vue入门(一)
    基于Vue官网教程(1-9)的自学笔记,记录自己对概念的粗浅理解。欢迎交流,如有不对请留言指正~目录1、单文件组件2、选项式API3、声明式渲染:4、v-model5、v-for渲染列表/数组6、compute计算属性计算属性便利在哪?7、模板引用1、单文件组件Vue的单文件组件会将一个组件......
  • Java基础入门day19
    day19面向对象的三大特性三大特性封装继承多态封装packagecom.saas;​publicclassStudent{​  Stringname;  intage;  doublescore;  booleansex;}packagecom.saas;​publicclassTestEncapsulation{​  publicsta......
  • python3最全知识点,从入门到开车就是这么简单(建议收藏)
    前言:此文是自己学习python过程中的笔记和总结.适合有语言基础的人快速了解python3和没基础的作为学习的大纲了解学习的方向、知识点;笔记是从多本书和视频上学习后的整合版。(一)初识python1、一般文件以.py为格式;用#作注释.2、一般对象不用特别声明,python会自动识别;一......