排序
【算法】【Python】N皇后问题的三种解法
本文分析了N皇后问题的三种解法:回溯法通过逐行尝试并安全检测实现,时间复杂度O(n!)但实现简单;分支限界法利用列和对角线标记数组将安全判断优化至O(1),通过空间换时间显著提升速度;位运算...
【C】判断回文数
#include <stdio.h> bool fun(int n) { int a = 0; int num = n; while (n > 0) { a = a * 10 + n % 10; n = n / 10; } if (a==num) { return true; } else { return false; } } int main() ...
【算法】【Python】蓝桥杯Python组比赛技巧
本文介绍了Python在蓝桥杯比赛中的常用技巧,包括序列翻转、数字进制转换、数学表达式解析、自定义排序、遍历序列、数据结构操作、组合与排列生成、双端队列、阶乘计算、日期处理、字符计数、有...
【模拟】二进制求和
#include <iostream> using namespace std; string addBinary(string a, string b){ string res; int carry = 0; // 进位 int i = a.size() - 1; int j = b.size() - 1; while(i >= 0 || j...
【C++】过河卒问题
无马情况 #include <iostream> // 定义棋盘大小 #define MAXSIZE 30 using namespace std; int main(){ int a[MAXSIZE][MAXSIZE]={0}; int n,m; // n,m为B点的坐标,A点默认为(0,0) cin >> n...
【C】五舍六入?
如果题目让你五舍六入,那么就没办法使用C++里的round函数了,只能选择一个通用的方法,示例如下: #include <stdio.h> #define PI 3.1415926 int main(){ double r,ans; scanf('%lf',&r...