2013-04-06 Robert Zhang
分析:运算时产生的大数可能会使32位整数溢出,需要使用64位的整数类型more ```cpp include include ifdef DEBUG include "../comm_headers/debug_helper.h" else define DEBUG_OUT(...) endif 继续阅读 »
2013-04-21 Robert Zhang
more ```cpp include include include using namespace std; class Card { public: char v; char t; Card(char av, char at) : v(av), t(at) {} Card() : v(0), t(0) {} }; 继续阅读 »
2013-04-28 Robert Zhang
more ```cpp include include using namespace std; void hartal(vector & days, int h) { int n = days.size(); int t = h - 1; while (t < n) { int r = t % 7; if (r != 5 && r != 6) days[t] = true; t += h; } } 继续阅读 »
2013-07-01 Robert Zhang
分析:先考虑一个例子: x=babgbag z=bag 答案是5,如何数数? 假设函数times(x, z)返回z在x中的次数(z可以是字符串也可以是字符——后者相当容易处理),容易得到递归解(伪代码):more cpp times(x, z) { if z.size == 1 return times(x, z[0]) //寻找字符z[0]在串x中出现的次数 s = 0 for i = 0; i < x.size; i++ if x[i] == z[0] //s[i, j]表示s从索引i开始到j结束(包括j在内)的子串,索引-1的位置指向串的最后一个字符 s += tim 继续阅读 »
2017-05-29 Robert Zhang
此题最简单、直观的办法是递归求解: more ```cpp vector a; //待登船的汽车长度(单位厘米)数组 int L; //车道长度,单位厘米 //当左右两个车道可用容量分别为left、right时, //从a[i]到a[n - 1]可登船的最多汽车数 int solve(int i, int left, int right) { if (i >= a.size() || (a[i] > left && a[i] > right)) return 0; int l = 0; int r = 0; //如果a[i]放在左边 if (a[i] <= left) l = solve(i 继续阅读 »
2013-05-03 Robert Zhang
more ```cpp include include include include using namespace std; const char * values[] = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"}; const char * suits[] = {"Clubs", "Diamonds", "Hearts", "Spades"}; 继续阅读 »
2013-05-05 Robert Zhang
分析:注意到“the quick brown fox jumps over the lazy dog”包含了全部26个英文字母,所以只要找到一句相匹配的密文,就可以解密全部了。more ```cpp include include include include include 继续阅读 »
2013-06-23 Robert Zhang
分析:分解质因数,求各位数字之和。如果担心当n等于10亿时,Smith数的计算会使unsigned int溢出,可以先试算一下——其实不小于10亿的最小Smith数是1000000165,不算大。more ```cpp include include include include 继续阅读 »
2017-01-20 TinyWu
vni more ```cpp /***************************************************************************** * Vni Basic tool library * * Copyright (C) 2017 Vless Inc * * 继续阅读 »
2016-11-15 ruki
最近对xmake.lua的工程描述语法进行了增强,现已可以同时支持两种不同语法风格。 set-add描述风格 key-val描述风格 set-add描述风格 这种是xmake经典的设置风格,例如: lua target("test") set_kind("static") add_defines("DEBUG") add_files("src/*.c", "test/*.cpp") 优势:控制灵活,可以根据各种条件,通过if-then进行灵活的条件编译,可以驾驭各种高度复杂的配置需求。 劣势:作用域控制不明显,需要手动规范化缩进 key-val描述风格 这种是xmake最近新加的风格,例如: l 继续阅读 »