当前位置: 首页 > news >正文

每日刷题c++

快速幂

#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

#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

#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;
}

http://www.xdnf.cn/news/705889.html

相关文章:

  • UE5蓝图中播放背景音乐和使用代码播放声音
  • 100个 Coze 智能体实战案例
  • tiktoken学习
  • C54-动态开辟内存空间
  • Java交互协议详解:深入探索通信机制
  • 【Linux笔记】Shell-脚本(下)|(常用命令详细版)
  • 基于随机函数链接神经网络(RVFL)的锂电池健康状态(SOH)预测
  • ICASSP2025丨融合语音停顿信息与语言模型的阿尔兹海默病检测
  • .NET 开源工业视觉系统 OpenIVS 快速搭建自动化检测平台
  • 智能仓储落地:机器人如何通过自动化减少仓库操作失误?
  • 自动化中的伦理:驯服人工智能中的偏见与守护合规之路
  • Magentic-UI:人机协作的网页自动化革命
  • Mybatis中实现多表查询(多对一)
  • 【Hive 运维实战】一键管理 Hive 服务:Metastore 与 HiveServer2 控制脚本开发与实践
  • 上传图片转成3D VR效果 / 用photo-sphere-viewer实现图片VR效果
  • HTML、XML、JSON 是什么?有什么区别?又是做什么的?
  • 在 RedHat 系统(RHEL 7/8/9)中安装 ​​pythonnet​​ 和 ​​.NET Core​​ 的完整指南
  • 算法打卡第10天
  • Linux `cp` 命令深度解析与高阶应用指南
  • dify 配置访问前缀
  • WPF 按钮点击音效实现
  • 性能优化深度实践:突破vue应用性能
  • C# 打印PDF的常用方法
  • JS入门——JS引入方式
  • Qt Creator调用Python代码
  • 微信小程序(uniapp)实现腾讯云 IM 消息撤回
  • 本地部署消息代理软件 RabbitMQ 并实现外部访问( Windows 版本 )
  • stm32cube ide如何生成LL库工程
  • 云原生时代 Kafka 深度实践:02快速上手与环境搭建
  • 公司数据不泄露,DeepSeek R1本地化部署+web端访问+个人知识库搭建与使用