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

每日刷题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.lryc.cn/news/2392109.html

相关文章:

  • (自用)Java学习-5.19(地址管理,三级联动,预支付)
  • 【容器】docker使用问题处理
  • ChemDraw 2023|Win英文|化学结构编辑器|安装教程
  • Vue3实现提示文字组件
  • JAVA与C语言之间的差异(一)
  • 深入剖析 C 语言中的指针数组与数组指针
  • 4.1.1 Spark SQL概述
  • 【VSCode-Qt】Docker远程连接的项目UI文件在 VSCode 上无法预览
  • redis五种数据结构详解(java实现对应的案例)
  • Telnet 命令详解
  • 深度解析新能源汽车结构与工作原理
  • React 生命周期与 Hook:从原理到实战全解析
  • OpenSSL 与 C++ 搭建一个支持 TLS 1.3 的服务器
  • HOW - 简历和求职面试宝典(六)
  • 【机器学习基础】机器学习入门核心算法:逻辑回归(Logistic Regression)
  • 深入理解设计模式之命令模式
  • 智能仓储落地:机器人如何通过自动化减少仓库操作失误?
  • Android 架构演进之路:从 MVC 到 MVI,拥抱单向数据流的革命
  • [低代码表单生成器设计基础]ElementUI中Layout布局属性Form表单属性详解
  • 数据结构7——二叉树
  • 从“被动养老”到“主动健康管理”:平台如何重构代际关系?
  • Java 中的 synchronized 和 Lock:如何保证线程安全
  • 贪心算法应用:最大匹配问题详解
  • 爬虫IP代理效率优化:策略解析与实战案例
  • 豆瓣电视剧数据工程实践:从爬虫到智能存储的技术演进(含完整代码)
  • 【HW系列】—C2远控服务器(webshell链接工具, metasploit、cobaltstrike)的漏洞特征流量特征
  • 5.28 孔老师 nlp讲座
  • 基于微信小程序的漫展系统的设计与实现
  • 打卡day39
  • 基于Web的分布式图集管理系统架构设计与实践