随笔分类 - 一刀999,砍题大法
摘要:有一个n*m的棋盘(1<n,m<=400),在某个点上有一个马,要求你计算出马到达棋盘上任意一个点最少要走几步 输入格式 一行四个数据,棋盘的大小和马的坐标 输出格式 一个n*m的矩阵,代表马到达某个点最少要走几步(左对齐,宽5格,不能到达则输出-1) 输入输出样例 输入 #1复制 3 3 1 1
阅读全文
摘要:K(1≤K≤100)只奶牛分散在N(1≤N≤1000)个牧场.现在她们要集中起来进餐.牧场之间有M(1≤M≤10000)条有向路连接,而且不存在起点和终点相同的有向路.她们进餐的地点必须是所有奶牛都可到达的地方.那么,有多少这样的牧场呢? 第1行输入K,N,M.接下来K行,每行一个整数表示一只奶牛所
阅读全文
摘要:#include <iostream> #include <cstdio> #include<iomanip> using namespace std; int b[9]; int ans; int n; int panduan(int a[], int n)//1不在,0在 { bool x =
阅读全文
摘要:#include <iostream> #include <cstdio> using namespace std; int b[100]; int c[100]; int a[3] = { 1,2,3 }; int ans; int n; void fun(int depth, int sum)
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; int n=0,k=0,ans=0; int a[25]; bool panduan(int x) { for(int i=2;i<floor(sqrt(x));i++) { if(x%i==0) retur
阅读全文
摘要:#include <cstdio> #include <queue> #include <utility>//pair using namespace std; typedef pair<int, int> pii; const int N = 405; int d[N][N]; int main(
阅读全文
摘要:#include <iostream> #include <cstdio> using namespace std; #define PI 3.1415927 int main() { double a; while(scanf("%lf",&a)!=EOF) { double s=4*PI*a*a
阅读全文
摘要:法一:scanf对于数字的读取来说,不读入空白和换行符,但读字符的时候则会读入 法二 输入两组数据后,才出现结果,两种方法中的printf中的换行符都是刷新缓冲区的作用
阅读全文
摘要:#include <iostream> #include <cstdio> #include <algorithm> using namespace std; char a,b,c; int main() { while(scanf("%c%c%c\n",&a,&b,&c)!=EOF)//这里读取格
阅读全文
摘要:题目描述 一矩形阵列由数字 00 到 99 组成,数字 11 到 99 代表细胞,细胞的定义为沿细胞数字上下左右若还是细胞数字则为同一细胞,求给定矩形阵列的细胞个数。 输入格式 第一行两个整数代表矩阵大小 nn 和 mm。 接下来 nn 行,每行一个长度为 mm 的只含字符 0 到 9 的字符串,代
阅读全文
摘要:dfs基本套路 void dfs()//参数用来表示状态 //从功能单元去理解 { if(到达终点状态) { ...//根据题意添加 return; } if(特殊状态) //剪枝 return ; if(如果不越界且合法) { for(扩展方式) //搜周围 { if(扩展方式所达到状态合法) {
阅读全文
摘要:转载题解: https://blog.csdn.net/qq742762377/article/details/80778136(作者:X丶) 此题核心在于: 1.用二位数组存储编码头 2.memset(a,0,sizeof(a));只能初始化为0(因为它是靠二进制来完成的) 另外需要注意一个函数:
阅读全文
摘要:#include<iostream> using namespace std; //八皇后问题 //思路:8*8的dfs,求结果个数问题(外加上条件减支即可) //不用开二维数组 int a[8] = {0}; //a数组用来记录8行中每行皇后的位置,比如a[2]=3就表示第二行的皇后在第三个位置
阅读全文
摘要:关于dfs: 例题:计算细胞数量 可以用递归实现,也可以不用递归实现(队列) 一矩形阵列由数字 00 到 99 组成,数字 11 到 99 代表细胞,细胞的定义为沿细胞数字上下左右若还是细胞数字则为同一细胞,求给定矩形阵列的细胞个数。 输入格式 第一行两个整数代表矩阵大小 nn 和 mm。 接下来
阅读全文
摘要:#include <iostream>#include <cstdio>using namespace std;int mem[200];//开记忆数组int fib(int n){ if(mem[n]!=0) return mem[n]; //每次先从记忆数组里寻找,如果有,直接用就行 if(n=
阅读全文
摘要:#include <iostream> #include <cstdio> using namespace std; int n,r; int ans[100]; int fun(int i,int x) //功能单元:根据现在的深度和上一次选出来的数字,决定下一次选出的数 { if(i==r) {
阅读全文