经典代码
shy
程序员shy
2021年CSDN博客之星参与奖,「 游戏人生 」系列作者,立志写傻瓜也能看懂的技术文章,博客目标打造前端程序员从小白到大师全流程学习路线。有问题可私聊
展开
-
经典八皇后
八皇后 题目:输入一个n,代表n*n的棋盘(6 <= n <= 13),在棋盘上放置皇后,每行每列每条左右对角线只可有一个棋子,求总方案数,以及按行输出前三种棋子摆放的列数 思路:dfs深度搜索按行搜索,dfs内遍历每一列,判断是否可摆放 #include <iostream> using namespace std; const int maxn = 100; int a[maxn],b[maxn], c[maxn],d[maxn]; //a为每行棋子摆放的列数,b为每.原创 2021-12-05 17:18:42 · 222 阅读 · 0 评论 -
水仙花数~
水仙花数:水仙花数是指一个3位数,它的每个位上的数字的3次幂之和等于它本身 #include<iostream> using namespace std; int main() { for(int i = 100; i < 1000; i++) { int a = i % 10; int b = i / 10 % 10; int c = i / 100; if (a * a * a + b * b * b + c * c * c == i) cout <原创 2021-10-23 10:42:45 · 104 阅读 · 0 评论 -
猜数字(系统时间做种子)
/* 猜数字游戏 */ #include<iostream> using namespace std; #include<ctime> //时间种子所依赖的头文件 int main() { srand((unsigned int)time(NULL)); //随机数种子,利用当前系统时间生成随机数,防止每次随机数都一样 int num = rand() % 100 + 1; //生成0~99的随机数+1 while (1) { int k; ci.原创 2021-10-22 21:25:48 · 118 阅读 · 0 评论