当前位置: 首页 > 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;
}

相关文章:

  • 棋盘问题(放置棋子)
  • 【Phytium】飞腾FT2000/4 GPIO功能开发实例
  • Python实例题:Python实现Zip文件的暴力破解
  • 游戏盾在非游戏行业的应用实践与价值分析
  • leetcode:372. 超级次方(python3解法,数学相关算法题)
  • 【SQL】关键字
  • 在Spring Cloud中将Redis共用到Common模块
  • 健康管理系统的核心价值:降低成本,提升效率
  • leetcode701.二叉搜索树中的插入操作:迭代法利用有序性寻找空节点插入点
  • Java HashMap原理:高效键值存储的秘密
  • Spring AI(9)——MCP客户端
  • 4060显卡什么水平 4060显卡参数介绍
  • 【QT】理解QT机制之“元对象系统”
  • JavaSE:面向对象进阶之抽象类
  • [python] lock 解决线程安全问题
  • 信号与系统速成-1.绪论
  • Java面试八股(Java基础,Spring,SpringBoot篇)
  • json中对象转字符串和字符串转对象的方法
  • 【Linux系统移植】Cortex-A8 Linux系统移植(超详细)
  • Next.js 布局(Layout)与模板(Template)深度解析:从原理到实战
  • 公司做普通网站/百度一下百度搜索官网
  • 慈善会网站建设方案/营业推广的方式
  • 贵州网站优化/购买友情链接网站
  • 杭州优化公司在线留言/标题关键词优化报价
  • 惠州网站建设电话/百度网站推广价格查询
  • 网站制作和收费标准/泰安seo培训