- 博客(121)
- 资源 (2)
- 收藏
- 关注
原创 Python-Print 输出
print 默认输出是换行的,如果要实现不换行需要在变量末尾加上逗号 ,#!/usr/bin/python# -*- coding: UTF-8 -*-x="a"y="b"# 换行输出print xprint yprint '---------'# 不换行输出print x,print y,# 不换行输出print x,y以上实例执行结果为:ab---------...
2018-05-18 00:01:58
515
原创 Python 引号
Python 可以使用引号( ' )、双引号( " )、三引号( ''' 或 """ ) 来表示字符串,引号的开始与结束必须的相同类型的。其中三引号可以由多行组成,编写多行文本的快捷语法,常用于文档字符串,在文件的特定地点,被当做注释。...
2018-05-17 23:59:35
550
原创 Python多行语句
Python语句中一般以新行作为语句的结束符。但是我们可以使用斜杠( \)将一行的语句分为多行显示,如下所示:total = item_one + \ item_two + \ item_three...
2018-05-17 23:57:22
3837
原创 Python行和缩进
学习 Python 与其他语言最大的区别就是,Python 的代码块不使用大括号 {} 来控制类,函数以及其他逻辑判断。python 最具特色的就是用缩进来写模块。缩进的空白数量是可变的,但是所有代码块语句必须包含相同的缩进空白数量,这个必须严格执行。...
2018-05-17 23:55:51
506
原创 Python 标识符
在 Python 里,标识符由字母、数字、下划线组成。在 Python 中,所有标识符可以包括英文、数字以及下划线(_),但不能以数字开头。Python 中的标识符是区分大小写的。以下划线开头的标识符是有特殊意义的。以单下划线开头 _foo 的代表不能直接访问的类属性,需通过类提供的接口进行访问,不能用 from xxx import * 而导入;以双下划线开头的 __foo 代表类的私有成员;以...
2018-05-17 23:53:39
522
原创 python-02
交互式编程不需要创建脚本文件,是通过 Python 解释器的交互模式进来编写代码。linux上你只需要在命令行中输入 Python 命令即可启动交互式编程。脚本式编程 所有 Python 文件将以 .py 为扩展名。python test.py./test.py...
2018-05-17 23:51:48
162
原创 Python
Python中默认的编码格式是 ASCII 格式,在没修改编码格式时无法正确打印汉字,所以在读取中文时会报错。解决方法为只要在文件开头加入 # -*- coding: UTF-8 -*- 或者 #coding=utf-8 就行了...
2018-05-17 23:23:33
178
原创 十三水--全顺牌型
bool CGameLogic::IsAllLine(BYTE cbCard[], BYTE cbCount, bool bSameColor){ if (cbCount == 0) return true; if (cbCount != 3 && cbCount != 5 && cbCount != 8 && cbCount != 10 &...
2018-05-13 21:25:14
1101
原创 带财神和白搭胡牌算法
//分析扑克bool CGameLogic::AnalyseCard(const BYTE cbCardIndex[MAX_INDEX], tagWeaveItem WeaveItem[], BYTE cbWeaveCount, CAnalyseItemArray & AnalyseItemArray){ //计算数目 BYTE cbCardCount=0; for (BYTE i=0;i...
2018-05-07 02:39:06
682
1
原创 LeetCode第797题 All Paths From Source to Target
class Solution {public: vector<vector<int>> paths; void findPath(vector<vector<int>> &graph ,vector<int> path,int x,int target) { if(x==target) ...
2018-04-07 21:25:56
216
原创 动态规划
copy#include <iostream> #include <algorithm> using namespace std; #define MAX 101 int D[MAX][MAX]; int n; int maxSum[MAX][MAX]; int main(){ int i,j; ...
2018-04-07 12:55:41
146
原创 LeetCode 789
class Solution {public: bool escapeGhosts(vector<vector<int>>& ghosts, vector<int>& target) { int myDistance=fabs(target[0])+fabs(target[1]); for(int i=0;i&...
2018-04-06 22:30:35
227
原创 DFS
#include <iostream>#include <stack>#define N 5using namespace std;int maze[N][N] ={ {0,1,1,0,0}, {0,0,1,0,1}, {0,0,1,0,0}, {1,1,0,0,1}, {0,0,1,0,0}};int visited[N+1]={0};void DFS...
2018-04-06 16:08:40
148
原创 BFS
#include <iostream>#include <queue>#define N 5using namespace std;int maze[N][N]={{0,1,1,0,0},{0,0,1,1,0},{0,1,1,1,0},{0,0,1,1,0}};int visited[N+1]={0};void BFS(int start){ queue<int...
2018-04-06 15:36:14
145
原创 LeetCode787题
There are n cities connected by m flights. Each fight starts from city u and arrives at v with a price w.Now given all the cities and fights, together with starting city src and the destination dst, y...
2018-04-06 14:06:15
409
原创 LeetCode第676题
Implement a magic directory with buildDict, and search methods.For the method buildDict, you'll be given a list of non-repetitive words to build a dictionary.For the method search, you'll be given a w...
2018-04-05 21:37:49
244
原创 LeetCode 695. Max Area of Island
Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrou...
2018-04-02 00:54:11
153
原创 LeetCode第628题
Given an integer array, find three numbers whose product is maximum and output the maximum product.Example 1:Input: [1,2,3]Output: 6Example 2:Input: [1,2,3,4]Output: 24Note:The length of the given...
2018-04-01 17:11:05
146
翻译 leetcode605题(2 Keys Keyboard)
class Solution {public: int minSteps(int n) { if (n <= 1) { // 如果需要的长度小于等于1,那就不需要操作了,直接返回0 return 0; } int ans = 0; // 初始化操作的次数 int left = n - 1; /...
2018-03-26 22:30:37
146
翻译 LeetCode605题 (2 Keys Keyboard)
int MAX = 1001;class Solution {public: int dp(int n, int have, int c) { //have代表已经有了几个A,c代表当前复制板上有几个A if (n == have) { // 如果已经到达目标,返回0 return 0; } else if (n < ha...
2018-03-26 22:14:14
165
原创 lua
lua的特点:轻量级,可扩展性,支持面向过程编程和函数式编程自动内存管理:提供一种通用类型的表,用于实现数组,哈希表,集合和对象。语言内置模式匹配;闭包(closure);函数也可以看做一个值;提供多线程(协同进程,并非操作系统所支持的线程)支持;通过闭包和table可以很方便地支持面向对象编程所需要的一些关键机制,比如数据抽象,虚函数,继承和重载等...
2018-02-11 18:02:51
200
原创 leetcode第十题
Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input st
2018-02-05 00:11:41
455
原创 leetcode第一题(TWO SUM)
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same
2018-02-03 23:29:42
172
原创 麻将的胡牌算法
//分析扑克bool CGameLogic::AnalyseCard(BYTE cbCardIndex[MAX_INDEX], tagWeaveItem WeaveItem[], BYTE cbWeaveCount, CAnalyseItemArray & AnalyseItemArray){//计算数目BYTE cbCardCount=0;for (BYTE i=0;ic
2018-01-06 23:49:23
1035
原创 Fail-soft alpha-beta
alphabeta(depth,alpha,beta),如果一开始就将alpha,beta限定得较小,那么整个搜索过程将减去更多的枝条。但是,可能得到3种结果,一种是要找目标就落在alpha,beta的范围之内,这样花费了很少的时间就得到结果,还有两种情况就那么幸运了,要找的值要么比alpha小,或者比beta大.int FAlpah(int depth,int alph
2017-05-21 04:14:50
1294
原创 负极大值搜索引擎
//alphabeta的过程//depth是当前搜索距离叶子点的层数//alpha是搜索的上边界//beta是搜索的下边界int CAlphaBetaEngine::alphabeta(int depth,int alpha,int beta){ int score; int Count,i; BYTE type; i=IsGam
2017-05-21 03:25:53
506
原创 负极大值搜索
Alpha-Beta搜索需要遍历的节点远远少于极大极小算法所遍历的节点:在任何一层都只进行beta剪枝,它会同负极大值算法一样简洁: int alphabeta(int nPlay,int alpha,int beta) { if(Game over) return eval(); //胜负已分,返回估值 if(nPl
2017-05-21 02:31:02
1724
原创 Alpha-Beta
人机对弈的程序:1)某种在机器中表示棋局的方法,能让程序知道博弈的状态2)产生合法走法的规则,以使博弈公正地进行,并可判断人类对手是否乱走。3)从所有合法的走法中选择最佳的走法的技术。4)一种评估局面优劣的方法,用以同上面的技术配合做出只能的选择。5)一个界面,有了它,这个程序才能用。Alpha-Beta搜索 在极大极小搜索的过程中,存在一定程度的
2017-05-21 00:16:39
368
原创 智能指针
应使用哪种智能指针呢?如果程序要使用多个指向同一个对象的指针,应选择shared_ptr.这样的情况包括:一个指针数组,并使用一些辅助指针来标识特定的元素,如最大的元素和最小的元素:两个对象包含都指向第三个对象的指针:STL容器包含指针。很多STL算法都支持复制和赋值操作,这些操作可用于shared_ptr,但不能用于unique_ptr和auto_ptr.如果编译器没有提供share
2017-04-09 00:17:19
227
原创 类型转换符
如果你使用的编译器缺乏对新的类型转换方式的支持,你可以使用传统的类型转换方法代替转换语法:#define static_cast(TYPE,EXPR) ((TYPE)(EXPR))#define const_cast(TYPE_EXPR) ((TYPE)(EXPR))#define reinterpret_cast (TYPE,EXPR) ((TYPE)(EXPR))你可
2017-04-04 20:29:50
445
原创 尽量使用C++风格的类型转换
四个操作符:static_cast,const_cast,dynamic_cast和reinterpret_cast在大多数情况下,对于这些操作符你只需要知道原来你习惯于这样写:(type)expression而现在你总应该这样写:static_cast (expression)假设你想把int转换成double,以便让包含int类型的变量的表达式产生出浮点数值的结果。如
2017-04-04 19:44:20
303
原创 正确地尾调用
Lua支持“尾调用消除”当一个函数调用是另一个函数的最后一个动作时,该调用才算是一条“尾调用”,以下代码对g的调用就是一条“尾调用”: function f(x) return g(x) end也就是说,当f调用完g之后就再无其他事情可做了,因此在这种情况中,程序就不需要返回那个“尾调用”所在的函数了。所以在“尾调用”之后,程序也不需要保存任何关于该函数的栈信息了。
2017-03-27 23:20:21
1235
原创 非全局的函数
函数不仅可以存储在全局变量中,还可以存储在table的字段中和局部变量中。若要在Lua中创建这种函数,只需将常规的函数语法与table语法结合起来使用即可.Lib={}Lib.foo=function(x,y) return x+y endLib.goo=function(x,y) return x-y end还可以使用构造式Lib={ foo =f
2017-03-27 23:04:27
356
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人