每日刷题c++

快速幂

cpp 复制代码
#include <iostream>
using namespace std;
#define int long long
int power(int a, int b, int p)
{
    int ans = 1;
    while (b)
    {
        if (b % 2)
        {
            ans *= a;
            ans %= p; // 随时取模
        }
        a *= a;
        a %= p; // 随时取模
        b /= 2;
    }
    return ans;
}
signed main()
{
    int a, b, p;
    cin >> a >> b >> p;
    int res = power(a, b, p);
    res %= p;
    cout << a << "^" << b << " mod " << p << "=" << res;
    return 0;
}

Shortest path of the king

cpp 复制代码
#include <iostream>
#include <string>
using namespace std;
int res;
string s[1000];
string a, b;
int x, y;
int main()
{
    cin >> a >> b;
    x = (a[0] - 'a') - (b[0] - 'a');
    y = (a[1] - '0') - (b[1] - '0');
    while (x > 0 && y > 0)
    {
        s[res] = "LD";
        res++;
        x--;
        y--;
    }
    while (x < 0 && y < 0)
    {
        s[res] = "RU";
        res++;
        x++;
        y++;
    }
    while (x > 0 && y < 0)
    {
        s[res] = "LU";
        res++;
        x--;
        y++;
    }
    while (x < 0 && y > 0)
    {
        s[res] = "RD";
        res++;
        x++;
        y--;
    }
    while (x > 0)
    {
        s[res] = "L";
        res++;
        x--;
    }
    while (x < 0)
    {
        s[res] = "R";
        res++;
        x++;
    }
    while (y > 0)
    {
        s[res] = "D";
        res++;
        y--;
    }
    while (y < 0)
    {
        s[res] = "U";
        res++;
        y++;
    }
    cout << res << endl;
    for (int i = 0; i < res; i++)
    {
        cout << s[i] << endl;
    }
    return 0;
}

It's Time To Duel

cpp 复制代码
#include <iostream>
#include <vector>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> a(n + 1);
    bool flag = false;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if (a[i] == 0)
        {
            flag = true;
        }
    }
    if (!flag)
    {
        cout << "YES" << endl;
        return;
    }
    for (int i = 1; i < n; i++)
    {
        if (a[i] == a[i + 1] && a[i] == 0)
        {
            cout << "YES" << endl;
            return;
        }
    }
    cout << "NO" << endl;
    return;
}
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
相关推荐
xingyuzhisuan2 分钟前
适合微调Llama 3 70B模型的最低GPU配置推荐
运维·人工智能·算法·llama·gpu算力
IJCAST20 分钟前
Exploring the Frontiers of Complexity: Latest Research from IJCAST
人工智能·深度学习·神经网络·算法
所以遗憾是什么呢?20 分钟前
【题解】Codeforces Round 1097 (Div. 2, Based on Zhili Cup 2026) (致理杯) ABCDEF
数据结构·算法·acm·codeforces·icpc·ccpc·xcpc
wuweijianlove22 分钟前
算法优化中的控制流重构与分支预测机制的技术7
算法·重构
Yuezero_23 分钟前
Latent Manifold理论分析
人工智能·算法·机器学习
山北雨夜漫步23 分钟前
LangGraph
java·前端·算法
李佳鹏39 分钟前
96% 成功率,零标注数据:我用 PCA + Hungarian 解了这道几何题
算法
华盛AI41 分钟前
AI大模型竞品Anthropic Claude Opus 4.7深度分析
人工智能·算法
shehuiyuelaiyuehao1 小时前
算法21,搜索插入位置
python·算法·leetcode
Lazionr1 小时前
【栈与队列经典OJ】
c语言·数据结构