- 博客(81)
- 资源 (23)
- 收藏
- 关注
原创 栈与队列-密码翻译(数据结构基础 第3周)
问题描述 分析 题目很简单,有一点需要注意输入流的几个符号; cin >> str; //自动过滤空格、回车等 cin.get() 及getchar() 读取一个字符不跳过任何字符 cin.get(str)及cin.getline(str)可指定终止符,默认为‘\n’ 详情略去。 代码中要把cases:n后面的’\n’读走,否则会出错。 源码#include <iostrea
2016-06-30 23:25:01 1003
原创 栈与队列-顺序队列与链队列类模板的实现(数据结构基础 第3周)
这里Queue写的跟在STL中的使用方法基本上是一致的,经过了简单的测试。需要注意的是下面测试程序中并没有制定顺序列表(即数组)的大小,类模板中默认为10,当数据量超过指定大小时自动开辟一个更大的数组。 运行测试程序的结果: 源码 //Queue.h#pragma template <class T>class Queue {public: void clear();
2016-06-30 21:43:20 816
原创 栈与队列-出栈序列统计(数据结构基础 第3周)
问题描述 分析 这道题直觉就是使用递归做,关键是怎么构造递归函数,不难,详见代码。 源码#include <iostream>using namespace std;int counts=0;//参数istack:栈中数据个数;参数ostack:待放入栈中的数据个数//数据全部放入即表示生成一种序列void fun(int istack, int ostack) { if (
2016-06-30 19:57:14 961
原创 栈与队列-顺序栈与链栈类模板的实现(数据结构基础 第3周)
这是用C++编写的栈的类模板的实现,包括顺序栈和链栈,并进行了简单的测试。 代码中srrStack类和lnkStack类均继承于Stack类, Stack类可以看成是栈的逻辑结构(ADT抽象数据类型,Abstract Data Type)。注意这里实现是栈与我们在STL中使用的不太一样,比如:pop(T& item)可返回其栈顶值。 源码 //Stack.h#pragma template
2016-06-30 11:37:54 1551
原创 线性表-顺序表、链表类模板的实现(数据结构基础 第2周)
学习完课程后,自己用C++实现了简单的顺序表和链表,并用约瑟夫问题做了测试,不保证完全正确。 其中有一点需要注意一下:C++中类模板声明头文件和实现头文件不可以分离到.h和.cpp中,否则无法正常编译,详见:https://www.zhihu.com/question/20630104源码 1.顺序表 //seqlist.h#pragma once#include <iostream>us
2016-06-28 20:11:08 3575
原创 线性表-大整数乘法(数据结构基础 第2周)
问题描述: 分析 注意处理好进位、某一位原有数字及最高一位,常规题。 源码#include <iostream>#include <vector>#include <string>using namespace std;int main() { string s1, s2; cin >> s1 >> s2; int len1=s1.length()
2016-06-28 20:02:39 1326
原创 线性表-多项式加法(数据结构基础 第2周)
问题描述: 分析 这道题用map应该是最容易实现的,没用链表。源码#include <iostream>#include <map>using namespace std;int main() { int n; cin >> n; int value, power; while(n--) { map<int, int, greater<
2016-06-28 18:45:57 1164
原创 线性表-约瑟夫问题(数据结构基础 第2周)
问题描述: 分析 个人采用顺序表做的,此处要注意一点:在同一.cpp文件下,如果想要在main()函数后定义类模板而在main()函数内使用类模板,则必须在main()函数前写出类模板的完整声明,因为定义类对象的时候必须知道类的所有成员变量和成员函数。具体见代码。 源码 #include <iostream>#include <stdio.h>using namespace std
2016-06-28 10:38:05 2014
原创 期末考试-至少有多少只恼人的大青蛙?(算法基础 第10周)
问题描述: 分析 还没做,后几道题打算先不做了,可参考:程序设计实习上机练习43 至少有多少只恼人的大青蛙?(搜索+贪心,至今未解决) 源码 //来自http://blog.csdn.net/pku_zzy/article/details/51531877
2016-06-24 16:34:02 1566
原创 期末考试-怀表问题(算法基础 第10周)
问题描述: 分析 还没做,后几道题打算先不做了,可参考:poj 7222 怀表问题(递推+空间压缩)源码 //来自http://blog.csdn.net/pku_zzy/article/details/51594772
2016-06-24 16:17:33 1220
原创 期末考试-拯救公主(算法基础 第10周)
问题描述: 分析 迷宫问题 的复杂版,这道题自己还没做,后几道题打算先不做了,可参考;poj 4105 拯救公主(bfs+二进制状态压缩)源码 //来自http://blog.csdn.net/pku_zzy/article/details/51554623#include <iostream> #include <algorithm> #include <cstring
2016-06-24 16:01:48 2362
原创 期末考试-潘多拉星球的悬浮公寓(算法基础 第10周)
问题描述: 分析 类似于城堡问题,但比其更复杂。 还没做,后几道题打算先不做了,可参考:潘多拉星球的悬浮公寓(变式遍历地图) 源码 //来自http://blog.csdn.net/pku_zzy/article/details/51648457 #include<stdio.h>/* dir:u,d,l,r * face:ABDC,BFHD,FEGH,EACG,EFBA
2016-06-24 15:45:46 2730
原创 期末考试-献给阿尔吉侬的花束(算法基础 第10周)
问题描述: 分析 迷宫,广搜解决。可参见迷宫问题,略微改动。源码#include <iostream>#include <vector>#include <queue>using namespace std;//节点坐标及走到此节点的步数struct Node{ int x, y; int steps;};const int inf=50001;int dx
2016-06-24 15:26:09 1536
原创 期末考试-猴子吃桃(算法基础 第10周)
问题描述: 分析 这道题可以使用递归做,也可以顺着使用for循环来代替递归。 源码#include <iostream>using namespace std;//总共n个猴子,第i个猴子来的时候所剩的桃子个数int fun(int n){ int last=0; while(1){ last++; int cur=last*n+1
2016-06-24 11:23:10 1308
原创 期末考试-Minecraft(算法基础 第10周)
问题描述: 分析 这道题相对简单,而且数也不大。这里可以先把所有可能的结果都计算并保存在了数组里,没进一个输入数据直接输出结果。 源码#include <iostream>using namespace std;int n[1001];void fun() { for (int k=1; k<=1000; k++){ int minarea=100000;
2016-06-24 10:28:25 1183
原创 期末考试-复杂的整数划分问题(算法基础 第10周)
问题描述: 分析 依然使用动规来做,找下状态转移方程。 dp[num][k][b]表示将数num划分为k个数,且每个数不小于b。 第一问, dp[num][k][b]=dp[num-b][k-1][b]+dp[num][k][b+1]; 第二问, dp[num][k][b]=dp[num-b][k-1][b+1]+dp[num][k][b+1]; 第三问, dp[num][
2016-06-23 22:12:14 1040
原创 期末考试-简单的整数划分问题(算法基础 第10周)
问题描述: 分析 动规做法,找下规律: dp[num][k]=dp[num-k][k]+dp[num][k+1]; dp[num][k]表示对num划分,且划分后的数字里最小的数为k。 可参考UNIMODAL PALINDROMIC DECOMPOSITIONS 这道题,预期类似。 源码#include <iostream>#include <vector>using nam
2016-06-23 19:46:44 1230
原创 期末考试-最大公约数(算法基础 第10周)
问题描述: 分析 辗转相除法 源码 #include <iostream>using namespace std;int fun(int& a, int& b) { int temp; while(b){ temp = a%b; a=b; b=temp; } return a;}int main() {
2016-06-23 17:29:33 768 1
原创 期末考试-垃圾炸弹(算法基础 第10周)
问题描述: 分析 最简单粗暴的方法,直接枚举每一个坐标点。提交错误提示:wrong answer。POJ上也没有给错误测试数据。郁闷,先放这儿,改天再看。 源码 //提交提示:wrong answer#include <iostream>#include <vector>using namespace std;int d, n;struct Rubbish{ in
2016-06-23 16:59:26 2584
原创 二分与贪心-Gone Fishing(算法基础 第9周)
问题描述: 分析 共n个湖,h个小时的时间;每个湖首次可钓到fi条鱼,往后一次递减di条,从i湖走到i+1湖需ti×5分钟。问:指定时间内最多可钓多少条鱼。 参考代码;http://blog.csdn.net/lyhvoyage/article/details/23289531 。按他的方式,第一种方法测试超时,第二种使用优先队列方法可以通过。但自己写了两个,即使使用优先队列也会超时,
2016-06-23 14:16:02 1367
原创 二分与贪心-Yogurt factory(算法基础 第9周)
问题描述: 分析 共N周,单位牛奶牛奶每周保存的费用为S,第i周生产单位牛奶的成本C_i,第i周出售Y_i单位牛奶。问怎么生产可使成本最低。 使用贪心策略记录第i周的成本:minprice=min(c, minprice+S); 源码#include <iostream>#include <algorithm>using namespace std;int main() {
2016-06-23 10:07:49 809
原创 二分与贪心-Aggressive cows(算法基础 第9周)
问题描述: 分析 主要还是二分的思想;最后选择l还是r值作为结果的时候需要自己分析一下。 源码#include <iostream>#include <vector>#include <stdio.h> #include <algorithm>using namespace std;int N, C;int l, r, mid;//畜栏vector<int> stalls
2016-06-21 18:41:11 1026
原创 二分与贪心-誊写书籍(算法基础 第9周)
讲解 分析 关于此题的一部分理解详见注释 源码#include <stdio.h>#include <iostream>using namespace std;#define MAXM (500+10)int N, m, k;//每本书的页数int a[MAXM];//判断最大堆的页数小于等于ans是否可行bool check(long long ans)
2016-06-21 11:07:24 668
原创 55. Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if you are
2016-06-20 21:48:08 437
原创 广度优先搜索-迷宫问题(算法基础 第8周)
问题描述: 分析 使用广搜方法解决 源码#include <iostream>#include <cstring>#include <cstdio>#include <queue>using namespace std;int maze[5][5];int visited[5][5];struct Node{ int x, y; int steps;
2016-06-20 20:03:21 1296
原创 二分与贪心-雷达安装问题(算法基础 第9周)
讲解 分析 前面老师讲过使用贪心找到的并不一定是全局最优解,这里也不一定是全局最优解吧? 源码#include <stdio.h>#include <iostream>#include <algorithm>#include <math.h>using namespace std;#define MAXN (1000+10)//线段两端struct Node {
2016-06-20 16:33:14 1231
原创 二分与贪心-烘晾衣服(算法基础 第9周)
讲解 源码#include <stdio.h>#include <iostream>using namespace std;#define MAXN (100000+10)int n; //n件衣服int l, r, mid; //用于判定时间x,所考虑的左右及中值int k; //烘干机1分钟减少的水量int a[MAXN];//判断时间为ans是否可行bool c
2016-06-20 15:34:37 929
原创 二分与贪心-圣诞老人的礼物(算法基础 第9周)
讲解 源码#include <stdio.h>#include <iostream>#include <algorithm>using namespace std;#define MAXN (100+10)struct Box{ int v, w; //价值和重量 double density; //单位重量的价值};Box boxes[MAXN];i
2016-06-20 13:19:20 1116
原创 324. Wiggle Sort II
Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]….Example: (1) Given nums = [1, 5, 1, 1, 6, 4], one possible answer is [1, 4, 1, 5, 1, 6]. (2) Given nums = [1
2016-06-20 07:50:15 559
原创 广度优先搜索-Shredding Company(算法基础 第8周)
问题描述: 分析 没想到怎么用广搜做呀,直接枚举了,做法跟熄灯问题 一样。 源码 #include <iostream>#include <cstring>#include <algorithm>using namespace std;int field[5][6],filp[5][6];/*推测验证过程:根据第一行猜测*/int guess() { //
2016-06-19 20:29:37 748
原创 广度优先搜索-抓住那头牛(算法基础 第8周)
讲解 源码#include <iostream>#include <cstring>#include <queue>using namespace std;int N, K;const int MAXN=100000;int visited[MAXN+10];//判重标记,visited[i]=true表示i已经扩展过struct Step { int
2016-06-19 14:47:51 1450 1
原创 深度优先搜索2-Shredding Company(算法基础 第7周)
问题描述: 分析 题目中有一点感觉题意表达不是特别清晰:就是分割数字中不能用前导0(比如0123),但是它没说是否可以理解为:0, 123。从答案来看应该是不可以这样。 刚开始做的时候算法中忽略了所有0的存在,后来发现有问题调来调去,已经懵逼了。而且在POJ上测试,这道题还没有提供测试输入、输出。先跳过吧,贴一个别人的正确答案和自己的待完善答案。源码 正确答案来自:http:
2016-06-19 14:18:50 996
原创 350. Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection.Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].Note: Each element in the result should appear as many times as it
2016-06-18 21:44:37 561
原创 349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection.Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note: Each element in the result must be unique. The result can be in
2016-06-17 11:26:39 465
原创 300. Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence.For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing subsequence is [2, 3, 7, 101], therefore
2016-06-16 11:14:26 461
原创 309. Best Time to Buy and Sell Stock with Cooldown
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and
2016-06-15 14:52:38 783
原创 深度优先搜索2-Sudoku(算法基础 第7周)
讲解 源码#include <iostream>#include <vector>#include <algorithm>#include <cstring>using namespace std;short rowFlags[9][10]; //rowFlags[i][num]=1表示在第i行已经放了数字numshort colFlags[9][10]; //colFlags
2016-06-15 10:12:27 623
原创 357. Count Numbers with Unique Digits
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n.Example: Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, excludi
2016-06-14 20:48:08 1165
原创 322. Coin Change
You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money c
2016-06-14 15:43:11 602
原创 深度优先搜索1-A Knight's Journey(算法基础 第6周)
问题描述: 分析 题目挺难理解的,参考:https://www.slyar.com/blog/poj-2488-c.html 源码#include<iostream> #include <cstring>using namespace std; const int MAX=27;bool map[MAX][MAX];int dx[8]={-2, -2, -1, -1,
2016-06-14 00:49:52 781
Machine_Learning_Yearning_V0.5_01
2016-12-08
CS231n课程知识点汇总(lecture1-5).docx
2016-11-18
OpenCV3编程入门_毛星云编著
2015-12-05
基于Activex控件的C++、C#混合编程
2015-11-07
扫雷程序源码
2015-06-12
VS2010 VC++创建.rc资源文件(二)
2015-06-07
VS2010 VC++创建.rc资源文件(一)
2015-06-07
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人