【问题】
Given n points
on a 2D plane, find the maximum number of points that lie on the same straight line.
【思路】
对每一个点,分别计算这个点和其他所有点构成的斜率,具有相同斜率最多的点所构成的直线,就是具有最多点的直线。
【代码】
class Point:
def __in...
分类:
编程语言 时间:
2014-06-25 19:34:29
阅读次数:
246
刚学python,学到了有关于类和对象的地方。对一个概念有点模糊,后来通过实践编码找到一定规律
在python中
class test(object):
id=2
name='tt' list=['tt','dd']
def change(self,newA,new_id):
self.id=new_id
self.age=new...
分类:
编程语言 时间:
2014-06-25 19:29:20
阅读次数:
267
【问题】
Evaluate the value of an arithmetic expression in Reverse Polish Notation.
Valid operators are +, -, *, /.
Each operand may be an integer or another expression.
Some examples:
...
分类:
编程语言 时间:
2014-06-24 23:22:53
阅读次数:
331
python社区不乏幽默,先来看“python之道”这首诗。
导入this包:
import this
输出时一首诗,这首诗总结了Python的风格,可以指导Python程序员的编程。下面是译文:
The Zen of Python, by Tim Peters
Python之道
Beautiful is better than ugly.
美观胜于丑陋。
Explicit i...
分类:
编程语言 时间:
2014-06-24 22:40:23
阅读次数:
295
Python中一切皆是对象,每个对象都可以有多个属性。Python是如何管理这些属性呢?我们来探讨一下。
属性的__dict__系统
对象的属性包含两部分:类属性和对象属性。对象的属性可能来自于其类的定义,叫做类属性。类属性可能来自于类的定义自身,也可能来自父类。一个对象的属性还可能是该对象实例定义的,叫做对象属性。
对象的属性存储在对象的__dict__属性中。__dict__为一...
分类:
编程语言 时间:
2014-06-24 21:03:01
阅读次数:
218
【问题】
Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue",
return "blue is sky the".
【代码】
class Solution:
# @param s, a string
# @retu...
分类:
其他好文 时间:
2014-06-24 21:00:30
阅读次数:
168
最近突发奇想,希望能写一个通用的代码分析工具(有点言过其实了,其实是针对C代码的)。这几天看代码看的我头晕眼花,虽然有Source Insight的帮助,仍然觉得很多地方不够智能。现在主要遇到的问题有以下几个:
1,很多函数被定义为宏,然后被调用。这个就需要自己搜索到相应的定义,然后再去寻找调用处。
2,程序的结构中很多用到有限状态机,函数会被放到数组中。会遇到和上面同样的问题。
3,现有的...
分类:
其他好文 时间:
2014-06-24 20:07:07
阅读次数:
166
排序算法有不少,当然,一般的语言中都提供某个排序函数,比如Python中,对list进行排序,可以使用sorted(或者list.sort()),关于这方面的使用,在我的github代码库algorithm中有几个举例,有兴趣的看官可以去那里看看(顺便告知,我在Github中的账号是qiwsir,欢迎follow me)。但是,在某些情况下,语言中提供的排序方法或许不适合,必须选择某种排序算法。
...
分类:
其他好文 时间:
2014-06-24 18:33:33
阅读次数:
205
一:勘误
classifier类中: def fprob(self, f, cat):
if self.catcount(cat) == 0:
return 0
#notice: rember change int to double or float
# + 0.0 or *1.0 is ok, other wise, may get 0.
return self.fc...
分类:
其他好文 时间:
2014-06-24 17:49:42
阅读次数:
211
信号量semaphore
是一个变量,控制着对公共资源或者临界区的访问。信号量维护着一个计数器,指定可同时访问资源或者进入临界区的线程数。
每次有一个线程获得信号量时,计数器-1。若计数器为0,其他线程就停止访问信号量,直到另一个线程释放信号量。...
分类:
编程语言 时间:
2014-06-24 17:49:06
阅读次数:
256