- 博客(18)
- 资源 (1)
- 收藏
- 关注
原创 从棋盘原点开始扔骰子,到达某一个终点的概率
棋盘上共有2020个格子,从1开始顺序编号。棋子初始放在第1格,通过扔骰子决定前进格子数,扔出x点就前进x格。骰子有6面,分别对应1至6;质量均匀。当棋子到达2014或超过2014,游戏结束。那么,棋子刚好到达2014的概率与______最接近。2/31/21/32/71/61/7 最终游戏停止时停的位置是2014, 2015, 2016, 2017, 2018
2014-08-30 22:44:23 4376 3
转载 我使用过的Linux命令之join - 根据关键字合并数据文件
本文链接:http://codingstandards.iteye.com/blog/796299 (转载请注明出处) 用途说明Linux下最常用的数据文件格式是文本格式的,多个字段之间通过分隔符来区分,分隔符比如冒号(:)、制表符、空格等。/etc/passwd和/etc/group就是用:来分隔的,用MySQL的into outfile指令导出的数据通常是以制表符分
2014-08-30 00:18:50 592
转载 c++中,引用和指针的区别
指针和引用的区别(1)引用总是指向一个对象,没有所谓的 null reference .所有当有可能指向一个对象也由可能不指向对象则必须使用 指针. 由于C++ 要求 reference 总是指向一个对象所以 reference要求有初值. String & rs = string1; 由于没有所谓的 null reference 所以所以在使用前不需要进行测试其是
2014-08-29 20:58:53 479
原创 斐波拉切字符串统计个数 Fibonacci String
Problem: s0 = "a", s1 = "b", s2 = "ba", s3 = "bab", s4 = "babba", s4 = "babbabab", is called Fibonacci string. For the string with index n, given a string str = "bb", calculate how many times in the
2014-08-20 11:56:53 1011
转载 C++函数中那些不可以被声明为虚函数的函数
常见的不不能声明为虚函数的有:普通函数(非成员函数);静态成员函数;内联成员函数;构造函数;友元函数。1、为什么C++不支持普通函数为虚函数? 普通函数(非成员函数)只能被overload,不能被override,声明为虚函数也没有什么意思,因此编译器会在编译时邦定函数。2、为什么C++不支持构造函数为虚函数? 这个原因很简单,主要是从语义上考虑
2014-08-19 17:06:16 500
转载 【C++ Primer】 神秘的 sizeof(union) 、sizeof(struct) 和内存对齐技术
转自: http://blog.csdn.net/tianshuai1111/article/details/7576279
2014-08-19 00:26:43 1422
原创 线段树+离散化 IP地址段检查 SEGMENT TREE
Problem:Give a series of IP segments, for example, [0.0.0.1-0.0.0.3], [123.234.232.21-123.245.21.1]...Now there is a new IP, find which IP segment it's in ?Solution:First, we could map the end
2014-08-17 23:32:21 1711
原创 poj 1151 Atlantis 二分查找+离散化
AtlantisTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 17464 Accepted: 6654DescriptionThere are several ancient Greek texts that contain descriptions
2014-08-17 16:16:10 870
转载 为什么printf()用%f输出double型,而scanf却用%lf呢?
问:有人告诉我不能在printf中使用%lf。为什么printf()用%f输出double型,而scanf却用%lf呢?答:printf的%f说明符的确既可以输出float型又可以输出double型。 根据"默认参数提升"规则(在printf这样的函数的可变参数列表中 ,不论作用域内有没有原型,都适用这一规则)float型会被提升为double型。因此printf()只会看到双精度数。参见问题
2014-08-17 15:39:58 2245
转载 求正整数n划分因子乘积最大的一个划分及此乘积
问题描述: 给定一个正整数n, 则在n所有的划分中, 求因子乘积最大的一个划分及此乘积。 例如:8 = {8}, {7, 1}, {6, 2}, {5, 3}, {4, 4}, {3, 3, 2}, {2, 2, 2, 2} 等,那么在这些当中,3 * 3 * 2 的乘积最大,所以输出整个划分{3,3,2}和这个乘积18.算法分析: 一个结论:对于一
2014-08-17 10:02:40 2327
原创 C++ 多态 从不同数据源获取数据 多路归并
定义一个基类,用基类的指针分别指向不同的子类。。。#include #include #include #include using namespace std;class ListNode { public: int val; ListNode* next; ListNode(int x) : val(x), next(NULL) { }};
2014-08-16 10:07:54 1006
原创 分数转化为小数LeetCode 166. Fraction to Recurring Decimal
很水,但是需要练速度反映。。。15分钟全部写对!!!!!!!!!!!!#include #include #include using namespace std;class Decimal { public: int integer; bool recycle; vector decimal;};void toDecimal(int dividend,
2014-08-13 21:24:06 1332 1
原创 将n进制的数组压缩成字符串(0-9 a-z)同时解压
此类题目要明确两点:1. 打表:用数组下标索引字符,同时注意如果从字符对应回数字: int index = (str[i] >= '0' && str[i] 2. 注意低位在前还是高位在前,如果先来的是 低位*radix^i 即可。3. 统计每几个radix进制数组成一位,利用bits来表示。。。这破题主要是麻烦。。。#include #includ
2014-08-11 23:57:54 1572
原创 九度1535 重叠的最长字串 字符串哈希
题目描述:给定两个字符串,求它们前后重叠的最长子串的长度,比如"abcde"和“cdefg”是"cde",长度为3。输入:输入可能包含多个测试案例。对于每个测试案例只有一行, 包含两个字符串。字符串长度不超过1000000,仅包含字符'a'-'z'。输出:对应每个测试案例,输出它们前后重叠的最长子串的长度。样例
2014-08-10 15:02:34 921
原创 Given a tree, find the node with the minimum sum of distances to other nodes
O(n) complexity, have a traversal for the tree. Get the information of all children, then traverse the tree again. #include #include #include #include using namespace std;class Node { pub
2014-08-10 12:25:59 999
原创 C++ 文件include规则 常量定义
1. 将类的成员变量、类方法的定义写在.h中,将类方法的实现写在.cpp中,不要include .cpp文件,不要在.h文件中只写class MyClass; ,一定要写类成员变量和方法的全部定义!!!类方法的实现写在.cpp文件中。2. 类模版或者模版的定义一定要写在同一个.h中,不要写在.cpp中,不能分开写!!!可以参考 http://blog.csdn.net/ixsea/articl
2014-08-08 22:40:09 2916
原创 leetcode Word Break II
Give two versions of WA code:Version 1: Runtime Error: Find the bugclass Solution { public: void find(const string& s, const unordered_set& dict, vector& res) { int i, j, len = s.length();
2014-08-03 13:43:01 922
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人