Colin's blog

A football fan,an English lover and a coder


  • 首页

  • 分类

  • 关于

  • 归档

  • 标签

machine learning exercise - Coursera

发表于 2017-01-26   |   分类于 机器学习
第一次上机作业的任务: warmUpExercise.m plotData.m gradientDescent.m computeCost.m gradientDescentMulti.m computeCostMulti.m featureNormalize.m normalEqn.m warmUpExercise.m热身练习很简单,就是写一个单位矩阵: A = eye(5); plotData.m画图题,标上x,y轴的变量意义。 plot(x, y, 'rx', 'MarkerSize', 10); % Plot the data ylabel('Profit in $10,000s'); % Set the y?axis label xlabel('Population of City in 10,000s'); % Set the x?axis label computeCost.m代价函数 J = sum((X * theta - y).^2)/(2*m); gradientDescent.m梯度 ...
阅读全文 »

STL习题

发表于 2017-01-23   |   分类于 acm
复合词原题:UVa 10391 算法这题我一开始是拼接来做的结果超时,部分代码如下: for(int i = 0; i < cnt; i++){ for(int j = i + 1; j < cnt; j++){ s1 = words[i] + words[j]; s2 = words[j] + words[i]; if(dict.count(s1)) cout << s1 << "\n"; if(dict.count(s2)) cout << s2 << "\n"; } } 这里的时间复杂度有O(n²)了,换一种思考方式,改成字符串分割,因为每个字符串长度不一,所以时间复杂度为O(mn),结果通过了,其中用到了 string类里面的 substr()函数,具体用法参见下面的代码 程序代码#include <iostream> #include <string> #include <cstring> ...
阅读全文 »

c++课程设计

发表于 2016-12-28
原题要求:设计一个保留字的统计程序建立保留字文件;从源数据文件(C或C++语言程序)中,读取字符或字符串,与保留字文件中的保留字进行匹配比较,并统计计数。输出两张表文件:保留字计数,扫描程序的次数,非保留字计数。 想法我先说说我是第一天是怎么弄的,第一天。。。什么也没写出来,我连 保留字 是什么都不知道,后来百度后才知道 保留字就是c/c++关键字比如 int short while for,然后再看看题目,要求已经很明确了,建一个保留字文件以及一个c/cpp的源代码(任意的),通过程序筛选出保留字与非保留字,并且计数,最后分别用两个文件输出。所以,这个程序可以分成3部分: 文件读取 筛选以及计数 文件输出 先说文件输入输出,这个我是有点头疼的,之前c里面是用fread,fwrite两个函数,但这里显然不合适,你无法预测文档的大小。无奈,拿起上学期的c++书,翻到了文件输入输出流,书上的太简略,没有合适的代码,于是就先放在了这里。再来想一想第二个步骤,第二个步骤也是最难的部分,首先看筛选,如何将保留字与非保留字从源码里区分开来,和周围同学讨论后,他们是这样想的:通过文件操作将源码读 ...
阅读全文 »

16哈理工新生网络赛

发表于 2016-11-29   |   分类于 acm
本次新生赛题目还是很难的,部分题解还未看懂,先贴上来. 棋盘村原题:棋盘村 算法思想递推,比赛时用了bfs结果超时了,赛后看来还是递推简单明了.另外递推时要处理边界. 程序代码#include <iostream> #include <memory.h> using namespace std; int n,m,x,y; int g[100][100]; long long ans[100][100]; void robber_cover() { g[x][y]=0; g[x+2][y+1]=0; g[x+2][y-1]=0; g[x+1][y+2]=0; g[x+1][y-2]=0; g[x-2][y+1]=0; g[x-2][y-1]=0; g[x-1][y+2]=0; g[x-1][y-2]=0; } int main() { int T; scanf("%d",&T); while(T--) { memse ...
阅读全文 »

蓝桥杯周练(部分题)

发表于 2016-11-28   |   分类于 lanqiao
线段和点算法思想贪心 代码程序#include <iostream> #include <cstdio> #include <memory.h> #include <algorithm> #define mem(a,b) memset(a,b,sizeof(a)) bool vis[11000],dian[51000]; using namespace std; int n,m; struct s{ int l,r; }str[11000]; bool cmp(s a,s b) { return ((a.l<b.l)||(a.l==b.l&&a.r<b.r)); } int main() { mem(dian,false); mem(vis,false); scanf("%d%d",&n,&m); for(int i=0;i<n;i++) { int x; scanf("% ...
阅读全文 »
1…181920…23
Shen Hao

Shen Hao

Colin's blog | acm |c++

114 日志
6 分类
71 标签
GitHub
© 2017 Shen Hao
由 Hexo 强力驱动
主题 - NexT.Muse