随笔分类 -  ACM / dfs bfs 递推 分治

摘要:链接 优化: 1 唯一确定的数字 2 空的格子少的 int minv = 10,minx = -1,miny = -1; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(s[i * 9 + j] == '.'){ int c = 阅读全文
posted @ 2020-09-02 23:15 Hazelxcf 阅读(228) 评论(0) 推荐(0)
摘要:小H在一个划分成了n*m个方格的长方形封锁线上。 每次他能向上下左右四个方向移动一格(当然小H不可以静止不动), 但不能离开封锁线,否则就被打死了。 刚开始时他有满血6点,每移动一格他要消耗1点血量。一旦小H的 血量降到 0, 他将死去。 他可以沿路通过拾取鼠标(什么鬼。。。)来补满血量。只要他走到 阅读全文
posted @ 2020-04-18 17:27 Hazelxcf 阅读(247) 评论(0) 推荐(0)
摘要:https://vjudge.net/contest/367733#problem/B 一样的代码,自己的错了,难受 dalaode #include <iostream> #include<queue> #include<algorithm> #include<string.h> #include 阅读全文
posted @ 2020-04-12 13:19 Hazelxcf 阅读(168) 评论(0) 推荐(0)
摘要:#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; int n,k; char ch[10][10]; long long ans; int vis[10 阅读全文
posted @ 2020-04-12 09:56 Hazelxcf 阅读(155) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1045 #include <bits/stdc++.h> using namespace std; int n; char ch[10][10]; int dp[4][2] = {-1,0,1,0,0,-1,0,1 阅读全文
posted @ 2020-04-11 18:22 Hazelxcf 阅读(156) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1728 要注意题目给的输入顺序, dfs里面第三条如果不共线并且相应步数已经到了的话 #include <bits/stdc++.h> using namespace std; int t,m,n,k,x1,yy1 阅读全文
posted @ 2020-04-11 16:49 Hazelxcf 阅读(148) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/description/98/ 假设有A,B,C,D四个,在A上有n个。要移动到D上 在4塔的情况下 先移动i个到B上,在移动剩下的n - i个到D上(此时是在3塔的情况下) #include <bits/stdc++.h 阅读全文
posted @ 2020-03-27 18:25 Hazelxcf 阅读(175) 评论(0) 推荐(0)
摘要:https://www.luogu.com.cn/problem/P1760 用递归计算移动容易超时,借助公式 2^n - 1当数据太大时,公式无效,算不出大数例如: #include <bits/stdc++.h> using namespace std; int n; stringstream 阅读全文
posted @ 2020-03-27 18:24 Hazelxcf 阅读(137) 评论(0) 推荐(0)
摘要:https://www.luogu.com.cn/problem/P1908 归并排序是用来求逆序对的 归并排序的思想就是分治 #include <bits/stdc++.h> using namespace std; #define int long long const int maxn = 5 阅读全文
posted @ 2020-02-28 16:15 Hazelxcf 阅读(163) 评论(0) 推荐(0)
摘要:https://www.luogu.com.cn/problem/P1010 刚刚看到这个题时,有点懵,如果说这是个数学题 比如说7,应该先求出7 = 4 + 2 + 1; 即先分解出里面应该有最多的2的个数,然后再往下递推 算出2的多少次幂最接近给出的n; 用原来n的数减去2的幂,如果这个数大于2 阅读全文
posted @ 2020-02-28 15:43 Hazelxcf 阅读(179) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/99/ 假设现在有两个自然数A和B,S是AB的所有约数之和。 请你求出S mod 9901的值是多少。 输入格式 在一行中输入用空格隔开的两个整数A和B。 输出格式 输出一个整数,代表S mod 9901的值。 数据范围 阅读全文
posted @ 2020-02-23 17:00 Hazelxcf 阅读(251) 评论(0) 推荐(0)
摘要:战争中保持各个城市间的连通性非常重要。本题要求你编写一个报警程序,当失去一个城市导致国家被分裂为多个无法连通的区域时,就发出红色警报。注意:若该国本来就不完全连通,是分裂的k个区域,而失去一个城市并不改变其他城市之间的连通性,则不要发出警报。 输入格式: 输入在第一行给出两个整数N(0 < N ≤  阅读全文
posted @ 2020-02-20 20:37 Hazelxcf 阅读(326) 评论(0) 推荐(0)
摘要:P1019 单词接龙 #include <bits/stdc++.h> using namespace std; int n; string s[25]; int vis[25]; char ch; int mc[25][25];//重叠的最小部分 int an;//每次搜到的当前最长长串 int 阅读全文
posted @ 2020-02-11 19:19 Hazelxcf 阅读(144) 评论(0) 推荐(0)
摘要:P1135 奇怪的电梯 a == b这种情况要记得判断 #include <bits/stdc++.h> using namespace std; int n,a,b; int d[210][210]; int main(){ freopen("in","r",stdin); ios::sync_w 阅读全文
posted @ 2020-02-10 14:27 Hazelxcf 阅读(113) 评论(0) 推荐(0)
摘要:P1057 传球游戏 #include <bits/stdc++.h> using namespace std; int n,m; int dp[40][40]; int main(){ //freopen("in","r",stdin); ios::sync_with_stdio(0); cin 阅读全文
posted @ 2020-02-10 13:52 Hazelxcf 阅读(63) 评论(0) 推荐(0)
摘要:汉诺塔递归 #include <bits/stdc++.h> using namespace std; int n; /* 把 N- 1个从A经过C移动到B,最后一个从A到C N- 1个在B上,经过A移动到C */ void hanuoti(int n,char A,char B,char C){ 阅读全文
posted @ 2020-01-30 08:35 Hazelxcf 阅读(117) 评论(0) 推荐(0)
摘要:一群猴子要选新猴王。新猴王的选择方法是:让N只候选猴子围成一圈,从某位置起顺序编号为1~N号。从第1号开始报数,每轮从1报到3,凡报到3的猴子即退出圈子,接着又从紧邻的下一只猴子开始同样的报数。如此不断循环,最后剩下的一只猴子就选为猴王。请问是原来第几号猴子当选猴王? 输入格式: 输入在一行中给一个 阅读全文
posted @ 2019-12-16 09:44 Hazelxcf 阅读(175) 评论(0) 推荐(0)
摘要:https://www.luogu.com.cn/problem/P1464 记忆化搜索就是记录之前程序走过的, 当再次走到的时候 直接取出来即可 这个题 由2可以确定下来要将20步以内的状态记录下来 #include <bits/stdc++.h> using namespace std; int 阅读全文
posted @ 2019-08-07 14:22 Hazelxcf 阅读(108) 评论(0) 推荐(0)