本博客rss订阅地址: http://feed.cnblogs.com/blog/u/147990/rss
摘要: 假设有一个文件,文件的每一行包括n个整数,整数之间以一个空格隔开,文件总共有m行,但是事先不知道n,m。如何每次从文件中读取一行整数放到一个数组中。可以分为两步:1、首先从文件中读入一行字符串,2、然后从这一行字符串中解析出整数。对于第一步,我们可以有c、c++两种风格的做法c风格:FILE *fp... 阅读全文
posted @ 2014-05-12 21:19 tenos 阅读(18304) 评论(0) 推荐(1) 编辑
摘要: 题目链接Given a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word... 阅读全文
posted @ 2014-05-11 19:19 tenos 阅读(679) 评论(0) 推荐(0) 编辑
摘要: 题目链接The set[1,2,3,…,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence... 阅读全文
posted @ 2014-05-11 16:49 tenos 阅读(6346) 评论(0) 推荐(0) 编辑
摘要: 根据网上的相关博客总结了一下机器学习中的这两个概念,参考博客见文末。生成模型:无穷样本==》概率密度模型 = 生成模型==》预测判别模型:有限样本==》判别函数 = 预测模型==》预测机器学习中的模型一般分为两类:判别模型、生成模型,这是对问题的两种不同的审视角度。假设我们要学习一个算法区分大象和狗... 阅读全文
posted @ 2014-05-10 22:03 tenos 阅读(5572) 评论(0) 推荐(3) 编辑
摘要: 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. Dete... 阅读全文
posted @ 2014-05-09 21:07 tenos 阅读(3492) 评论(0) 推荐(0) 编辑
摘要: 题目链接Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were ini... 阅读全文
posted @ 2014-05-07 23:13 tenos 阅读(935) 评论(0) 推荐(0) 编辑
摘要: 题目链接Given a collection of intervals, merge all overlapping intervals.For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18].对若干... 阅读全文
posted @ 2014-05-07 21:38 tenos 阅读(1787) 评论(2) 推荐(0) 编辑
摘要: 题目链接 Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguous subarray [4,−1,2... 阅读全文
posted @ 2014-05-07 12:48 tenos 阅读(886) 评论(0) 推荐(0) 编辑
摘要: 简单的以下面曲线拟合例子来讲:直线拟合后,相比原来的点偏差最大,最后一个图完全拟合了数据点偏差最小;但是拿第一个直线模型去预测未知数据,可能会相比最后一个模型更准确,因为最后一个模型过拟合了,即第一个模型的方差比最后一个模型小。一般而言高偏差意味着欠拟合,高方差意味着过拟合。他们之间有如下的关系: ... 阅读全文
posted @ 2014-05-06 21:43 tenos 阅读(11424) 评论(2) 推荐(0) 编辑
摘要: How do you know what machine learning algorithm to choose for your classification problem? Of course, if you really care about accuracy, your best bet... 阅读全文
posted @ 2014-05-06 20:53 tenos 阅读(1768) 评论(0) 推荐(0) 编辑
摘要: 目录:一、L0,L1范数二、L2范数三、核范数今天我们聊聊机器学习中出现的非常频繁的问题:过拟合与规则化。我们先简单的来理解下常用的L0、L1、L2和核范数规则化。最后聊下规则化项参数的选择问题。这里因为篇幅比较庞大,为了不吓到大家,我将这个五个部分分成两篇博文。知识有限,以下都是我一些浅显的看法,... 阅读全文
posted @ 2014-05-05 13:12 tenos 阅读(8122) 评论(6) 推荐(4) 编辑
摘要: Unique PathsA robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right a... 阅读全文
posted @ 2014-05-02 15:25 tenos 阅读(780) 评论(0) 推荐(0) 编辑
摘要: 题目链接Given a list, rotate the list to the right bykplaces, wherekis non-negative.For example:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL.首... 阅读全文
posted @ 2014-04-30 19:57 tenos 阅读(809) 评论(0) 推荐(0) 编辑
摘要: 比如对于数组[1,-2,3,5,-1,2] 最大子数组和是sum[3,5,-1,2] = 9, 我们要求函数输出子数组和的最大值,并且返回子数组的左右边界(下面函数的left和right参数).本文我们规定当数组中所有数都小于0时,返回数组中最大的数(也可以规定返回0,只要让以下代码中maxsum初... 阅读全文
posted @ 2014-04-28 23:29 tenos 阅读(18421) 评论(0) 推荐(5) 编辑
摘要: 求数组全排列(不包含或者包含重复元素) 求数组所有组合(相当于求集合的所有子集,不包含或者包含重复元素) 从n个数中选择k个的组合(不包含重复元素) 从n个数中选择k个的组合(包含重复元素) 【版权声明】转载请注明出处:http://www.cnblogs.com/TenosDoIt/p/3695472.html 阅读全文
posted @ 2014-04-27 23:39 tenos 阅读(6402) 评论(0) 推荐(1) 编辑
摘要: LeetCode:Combinations这篇博客中给出了不包含重复元素求组合的5种解法。我们在这些解法的基础上修改以支持包含重复元素的情况。对于这种情况,首先肯定要对数组排序,以下不再强调修改算法1:按照求包含重复元素集合子集的方法LeetCode:Subsets II算法1的解释,我们知道:若当... 阅读全文
posted @ 2014-04-27 23:33 tenos 阅读(4983) 评论(0) 推荐(1) 编辑
摘要: 定义二进制变量: 一般是以八进制或者十六进制来定义,八进制数以0开头,十六进制数以0x开头 例如int a = 0x80, 这里的80只能表示8个二进制位,它表示的是int的低8位,前面的24个二进制位补0,所以a = 128;也可以 a = –0x80, 此时a = -128;8进制同理 需要注意的是:如果0x…能够在整形内表示,则其默认是int,否则再看unsigned int能否表示... 阅读全文
posted @ 2014-04-27 20:43 tenos 阅读(10884) 评论(0) 推荐(2) 编辑
摘要: 题目链接Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see bel... 阅读全文
posted @ 2014-04-22 22:47 tenos 阅读(601) 评论(0) 推荐(0) 编辑
摘要: Search Insert PositionGiven a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if ... 阅读全文
posted @ 2014-04-22 21:43 tenos 阅读(819) 评论(0) 推荐(1) 编辑
摘要: 题目链接Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.For example:Input: ["tea","and","... 阅读全文
posted @ 2014-04-22 20:36 tenos 阅读(640) 评论(0) 推荐(0) 编辑
摘要: 题目链接Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are th... 阅读全文
posted @ 2014-04-20 14:42 tenos 阅读(535) 评论(0) 推荐(0) 编辑
摘要: 题目链接Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique lo... 阅读全文
posted @ 2014-04-19 23:56 tenos 阅读(18923) 评论(3) 推荐(2) 编辑
摘要: 题目链接There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should... 阅读全文
posted @ 2014-04-19 16:18 tenos 阅读(2344) 评论(0) 推荐(0) 编辑
摘要: 题目链接Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.合并k个有序的链表,我们假设每个链表的平均长度是n。这一题需要用到合并两个有序的链表子过程算法1... 阅读全文
posted @ 2014-04-18 14:33 tenos 阅读(7543) 评论(0) 推荐(1) 编辑
摘要: 题目链接Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.1为了操作... 阅读全文
posted @ 2014-04-18 13:33 tenos 阅读(1323) 评论(0) 推荐(0) 编辑
摘要: 题目链接Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. Afte... 阅读全文
posted @ 2014-04-15 22:28 tenos 阅读(908) 评论(0) 推荐(0) 编辑
摘要: 这篇文章分析一下链表的各种排序方法。以下排序算法的正确性都可以在LeetCode的链表排序这一题检测。本文用到的链表结构如下(排序算法都是传入链表头指针作为参数,返回排序后的头指针)struct ListNode { int val; ListNode *next; ListNode(int x) ... 阅读全文
posted @ 2014-04-15 16:34 tenos 阅读(91313) 评论(5) 推荐(9) 编辑
摘要: 这里不详细说明快速排序的原理,具体可参考here快速排序主要是partition的过程,partition最常用有以下两种写法第一种: int mypartition(vector&arr, int low, int high) { int pivot = arr[low];//选第一个元素... 阅读全文
posted @ 2014-04-14 22:06 tenos 阅读(14095) 评论(0) 推荐(1) 编辑
摘要: PermutationsGiven a collection of numbers, return all possible permutations.For example, [1,2,3] have the following permutations: [1,2,3], [1,3,2]... 阅读全文
posted @ 2014-04-13 19:49 tenos 阅读(9000) 评论(0) 推荐(1) 编辑
摘要: 3Sum ClosestGiven an arraySofnintegers, find three integers inSsuch that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution.For example, given array S = {-1 2 1 -4}, and target = 1. The sum that is clo... 阅读全文
posted @ 2014-04-07 00:21 tenos 阅读(10389) 评论(0) 推荐(1) 编辑
摘要: 题目链接Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the tw... 阅读全文
posted @ 2014-04-05 15:20 tenos 阅读(2506) 评论(0) 推荐(0) 编辑
摘要: 对于无向图算法1我们知道对于环1-2-3-4-1,每个节点的度都是2,基于此我们有如下算法(这是类似于有向图的拓扑排序):求出图中所有顶点的度,删除图中所有度 >&graph, int node, vector&visit, vector&father){ int n = graph.size(); visit[node] = 1; //cout"; tmp = father[tmp]; } cout >&graph){ int n = grap... 阅读全文
posted @ 2014-04-03 23:45 tenos 阅读(52206) 评论(2) 推荐(6) 编辑
摘要: 要求是该类不能被继承,但是能够像正常的类一样使用。那么一下方法就不符合题目要求:1、构造函数和析构函数设置为private。这样就不能定义一个类的实例2、类似于singleton模式那样,定义一个静态函数(或友元函数)来生成类的实例。这样只能通过new在堆上创建类可以如下设计这个类class Base{private: Base() {} ~Base() {} friend class FinalClass;};class FinalClass : virtual public Base{};int main(){ FinalClass *p = new Final... 阅读全文
posted @ 2014-04-02 23:35 tenos 阅读(3856) 评论(0) 推荐(0) 编辑
摘要: 单例模式,也叫单子模式,是一种常用的软件设计模式。在应用这个模式时,单例对象的类必须保证只有一个实例存在。许多时候整个系统只需要拥有一个的全局对象,这样有利于我们协调系统整体的行为。比如在某个服务器程序中,该服务器的配置信息存放在一个文件中,这些配置数据由一个单例对象统一读取,然后服务进程中的其他对象再通过这个单例对象获取这些配置信息。这种方式简化了在复杂环境下的配置管理。实现单例模式的思路是:一个类能返回对象一个引用(永远是同一个)和一个获得该实例的方法(必须是静态方法,通常使用getInstance这个名称);当我们调用这个方法时,如果类持有的引用不为空就返回这个引用,如果类保持的引用为空 阅读全文
posted @ 2014-04-01 22:35 tenos 阅读(1833) 评论(0) 推荐(1) 编辑
摘要: 我的windows多线程系列文章:windows多线程--原子操作windows多线程同步--事件windows多线程同步--互斥量windows多线程同步--临界区windows多线程同步--信号量windows 多线程: CreateThread、_beginthread、_beginthreadex、AfxBeginThread 的区别MoreWindows的多线程系列文章秒杀多线程面试题系列一 同步互斥区别同步:同步是指线程之间所具有的一种制约关系,一个线程的执行依赖另一个线程的消息,当它没有得到另一个线程的消息时应等待,直到消息到达时才被唤醒,即他们之间有先后关系。互斥:对于共享的进 阅读全文
posted @ 2014-03-15 23:24 tenos 阅读(3289) 评论(2) 推荐(2) 编辑
摘要: 推荐参考博客:秒杀多线程第三篇 原子操作 Interlocked系列函数 原子操作 VS 非原子操作原子操作就是不会被线程调度机制打断的操作,这种操作一旦开始,就一直运行到结束,中间不会有任何线程切换。 本文地址首先从一个简单的例子来看,1000个线程同时对一个全局变量(初始化为0)做++操作,最后我们期望的这个变量的值是1000,但是有时候结果却事与愿违: #include #include #include #include using namespace std;volatile int g_cnt;unsigned __stdcall threadFun(void *param){ . 阅读全文
posted @ 2014-03-15 20:03 tenos 阅读(3483) 评论(0) 推荐(1) 编辑
摘要: 推荐参考博客:秒杀多线程第六篇 经典线程同步 事件Event 事件是内核对象,多用于线程间通信,可以跨进程同步 事件主要用到三个函数:CreateEvent,OpenEvent,SetEvent,ResetEvent 本文地址 CreateEvent 函数功能... 阅读全文
posted @ 2014-03-14 23:06 tenos 阅读(6327) 评论(2) 推荐(1) 编辑
摘要: 关于互斥量的基本概念:百度百科互斥量 推荐参考博客:秒杀多线程第七篇 经典线程同步 互斥量Mutex 注意:互斥量也是一个内核对象,它用来确保一个线程独占一个资源的访问。互斥量与关键段的行为非常相似,并且互斥量可以用于不同进程中的线程互斥访问资源... 阅读全文
posted @ 2014-03-14 22:06 tenos 阅读(4195) 评论(0) 推荐(1) 编辑
摘要: 推荐参考博客:秒杀多线程第五篇 经典线程同步 关键段CS 关于临界区的观念,一般操作系统书上面都有。 适用范围:它只能同步一个进程中的线程,不能跨进程同步。一般用它来做单个进程内的代码快同步,效率比较高 windows中与临界区有关的结构是 CRITICAL_SECTION,关于该结构体的内部结构可参考here 使用时,主线程中要先初始化临界区,最后要删除临界区,具体使用见下面代码:... 阅读全文
posted @ 2014-03-14 21:21 tenos 阅读(2698) 评论(0) 推荐(0) 编辑
摘要: 推荐参考博客:秒杀多线程第八篇 经典线程同步 信号量Semaphore 首先先介绍和windows信号量有关的两个API:创建信号量、释放信号量 HANDLE WINAPI CreateSemaphore( msdn官网解释 _In_opt_ LPSECURITY_ATTRIBUTES lpSemaphoreAttributes ... 阅读全文
posted @ 2014-03-14 20:34 tenos 阅读(6235) 评论(0) 推荐(0) 编辑

本博客rss订阅地址: http://feed.cnblogs.com/blog/u/147990/rss

公益页面-寻找遗失儿童