- 博客(20)
- 资源 (4)
- 收藏
- 关注
原创 拓扑排序
http://bailian.openjudge.cn/practice/4084/ 这个题目要求输出时按照编号从小到大,只要把队列改成优先队列即可。 图的存储结构采用邻接表,为了方便,增加了一个记录节点入度的数组,当入度为0时,加入队列。 #include <bits/stdc++.h> using namespace std; #define maxV 110 vector<...
2019-02-25 23:30:01
198
原创 Tangled in Cables
http://bailian.openjudge.cn/practice/2075/ MST+prim #include <bits/stdc++.h> #define Inf 10000 using namespace std; int v, e; map<string, int> namemap; double fee; double weigh[510][510]; ...
2019-02-25 00:28:42
204
转载 Huffman编码树
http://bailian.openjudge.cn/practice/4080/ #include <bits/stdc++.h> using namespace std; int n, ans, x; int main() { cin >> n; priority_queue<int, vector<int>, greater<int&g...
2019-02-23 21:20:34
217
原创 神奇的口袋
http://bailian.openjudge.cn/practice/2755/ 动态规划的问题,构造F(w,k),表示用前k个物品装w体积的装法,可以选择装第k个和不装第k个,方程为 F[W][K]=F[W][K-1]+F[W-A[K]][K-1]; 代码采用递推的方法实现。 初始化时,当W=0,K&gt;=0,有1种装法,即什么都不装。 问题的解是F[40][K]; #include &l...
2019-02-23 20:12:45
270
原创 Charm Bracelet
http://bailian.openjudge.cn/practice/4131/ 还是动态规划,只不过记忆数组的空间过大,这个题目可以使用滚动数组实现,并且遍历的方向是从后往前,因为根据递推方程,位于i,j上方的i-1,j,以及左前方的i-1,j-w[i]是需要使用的,如果从前往后遍历,旧的数据也有可能被使用,但是已经被新值覆盖了,这样逻辑错误,所以从后往前,保证覆盖的数据都是当前轮次不会再用...
2019-02-23 20:12:04
136
原创 马走日
http://noi.openjudge.cn/ch0205/8465/ 也是一种深度搜索的问题,不过扩展方向不是上下左右,而是“日”字型,而且要求遍历全部,加个序号即可。 #include <bits/stdc++.h> int flag[15][15]; int T; int n,m,x,y; int count ; int dx[8] = { -2,-1,1,2,2,1,-1,...
2019-02-15 17:34:49
1013
原创 经典的八皇后问题
n皇后问题可以递归求解。类似的问题: http://noi.openjudge.cn/ch0205/1700/ http://noi.openjudge.cn/ch0205/1756/ #include <bits/stdc++.h> using namespace std; int queenPos[10]; int no = 0; void output() { printf("...
2019-02-15 13:16:49
224
原创 广度优先搜索BFS框架
广度优先搜索与深度优先搜索是两种不同的搜索方式。比如回答从地图上的某点到另外一点是否可达,一般可以采用深搜。而问从某点到另外点的最短路径长度可以采用广度搜索,因为在有解的前提下,广度优先搜索是按层遍历的,可以保证到达解时所用的路径最短。 下面的例子是抓住那头牛的ac代码,使用了广度优先搜索的方法解题。 #include <bits/stdc++.h> using namespace s...
2019-02-15 01:30:34
369
原创 大整数乘法
http://noi.openjudge.cn/ch0113/09/ 一个数的第i位和另一个数的第j位相乘所得的数,一定要累加到结果的第i+j位上,这里i,j都是从右往左的,从0开始计数。(北大程序设计导引及在线实践) m位和n位数相乘,乘积的结果最多是m+n位。 result数组要开成max的两倍。 #include &lt;string.h&gt; #include &lt;math.h&...
2019-02-15 01:24:12
147
原创 判决素数个数
http://noi.openjudge.cn/ch0113/10/ 题目很简单,写完WA,原因是没有判断X,Y的大小关系。 #include &lt;iostream&gt; #include &lt;algorithm&gt; #include &lt;string.h&gt; #include &lt;math.h&gt; #include &lt;stdli
2019-02-15 01:24:05
240
原创 判断元素是否存在
http://noi.openjudge.cn/ch0113/41/ 根据题意,可以知道既然k是属于M了,那么M中其他的元素应该比k都要大,因此可以通过递归来做。 递归出口是当x==k,说明找到对应的元素; 或者x-1不能被2或3整除,说明没有对应的元素; #include &lt;string.h&gt; #include &lt;math.h&gt; #include &lt;stdlib.h...
2019-02-15 01:23:47
1006
原创 熄灯问题
http://noi.openjudge.cn/ch0201/1813/ 还有很多熄灯类似的问题,都是大致的思路。 #include &lt;bits/stdc++.h&gt; int n;//行数 int map[MAX][MAX];//源数据 int temp[MAX][MAX];//拷贝基本数据,操作在这个数组,不破坏源数据 int switchs[MAX];//某一行的操作信息 int...
2019-02-15 01:22:53
167
原创 深度搜索dfs框架
很多题目比如问从A能否到达B,是可以采用DFS的方法求解的。 bool Dfs(int v){ if(v==END){//已经到达终点 return true; } if(used[v]){//已经走过的 return false; } used[v]=1; 对v的相邻节点u{ //一般都是上下左右四个方向 ...
2019-02-15 01:22:35
213
原创 打印月历
http://noi.openjudge.cn/ch0113/24/ 计算某年某月某日是星期几的方法: 基姆拉尔森计算公式 W= (d+2m+3(m+1)/5+y+y/4-y/100+y/400+1)%7 //C++计算公式 在公式中d表示日期中的日数,m表示月份数,y表示年数,W是0-6,0代表Sunday。 注意:在公式中有个与其他公式不同的地方: 把一月和二月看成是上一年的十三月和十四月,...
2019-02-09 01:34:27
1513
原创 6044:鸣人和佐助
http://noi.openjudge.cn/ch0205/6044/ 依然是BFS框架,但是这里有个新的约束条件,是查克拉,所以状态参数应该是R(x,y,k),因为相同x,y若有不同的查克拉,应该对应于不同的状态。注意这点即可。 #include <iostream> #include <algorithm> #include <string.h> #inc...
2019-02-01 13:28:29
434
原创 迷宫问题
框架依旧是BFS,不过本题需要输出路径,所以不能用c++自带的queue,因为那个pop之后就找不到了;应该使用一维数组来模拟一个队列,用数组中的下标来记录父节点,通过改变tail,head指针实现入队,出队的操作。 #include <iostream> #include <algorithm> #include <string.h> #include <...
2019-02-01 00:18:43
187
原创 抓住那头牛BFS
http://noi.openjudge.cn/ch0205/2971/ 通过广搜,本题一定有解的,且是最优解。 #include <iostream> #include <algorithm> #include <string.h> #include <math.h> #include <stdlib.h> #include <q...
2019-01-31 23:17:11
245
原创 4982:踩方格
http://noi.openjudge.cn/ch0206/4982/ 图的搜索类型。 #include <iostream> #include <algorithm> #include <string.h> bool flag[30][50]; int dfs(int i, int j, int step) { if (flag[i][j]) { ...
2019-01-31 12:10:10
215
原创 放苹果
http://noi.openjudge.cn/ch0202/666/ #include <iostream> #include <algorithm> #include <string.h> using namespace std; int place(int m, int n) { if (m == 0||n == 1) { return 1; } ...
2019-01-31 00:10:01
133
原创 1551:Sumsets
原题链接:http://noi.openjudge.cn/ch0305/1551/ 先把原来的数据排序 按照从后往前的顺序枚举,因为要求的d是最大的 a+b+c=d转化为a+b=d-c,变为两重循环,寻找a+b时,因为事先已经排好序,所以可以利用两边夹的思路,找到最终的位置。 #include <iostream> #include <algorithm> #inclu...
2019-01-30 22:48:45
416
银行业务模拟系统 python实现+分析报告
2021-08-06
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅