This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//最长回文串 | |
//有O(n)的Manacher算法,不过好难写。。。 | |
import scala.math; | |
object Palindrome | |
{ | |
def main(args : Array[String]) | |
{ | |
def isPalindrome(x : String): Boolean = | |
{ | |
x equals x.reverse |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//归并排序 | |
object MergeSort | |
{ | |
def main(args:Array[String]) { | |
val a = readLine split(" ") map(_ toInt) toList | |
val b = readLine split(" ") map(_ toInt) toList | |
def merge_sort(a : List[Int], b: List[Int]): List[Int] = { | |
a match { | |
case Nil => b | |
case _ => b match |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//瓶子问题 | |
import scala.annotation.tailrec | |
object Bottle | |
{ | |
val N_Bottle = 3 | |
def main(args : Array[String]) | |
{ | |
val n = readLine toInt | |
@tailrec | |
def solve(full : Int, empty : Int = 0, drinked : Int = 0) : Int = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding=utf-8 | |
import sys,re,os | |
import numpy as np | |
from scipy import stats | |
import matplotlib.pylab as plt | |
def draw_kde(grade): | |
gkde = stats.kde.gaussian_kde(grade) | |
ind = np.arange(0.,100.,0.01) | |
plt.plot(ind, gkde(ind), label='Gods\' Grade', color="g") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
import sys | |
import xml.etree.cElementTree as cElementTree | |
from pyquery import PyQuery | |
import multiprocessing as mp | |
import time | |
reload(sys) | |
sys.setdefaultencoding('utf-8') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
import sys | |
import xml.etree.cElementTree as cElementTree | |
from pyquery import PyQuery | |
import time | |
reload(sys) | |
sys.setdefaultencoding('utf-8') | |
start_time = time.time() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
import sys | |
import xml.etree.cElementTree as cElementTree | |
from pyquery import PyQuery | |
import time | |
import gevent | |
from gevent.queue import Queue, Empty | |
reload(sys) | |
sys.setdefaultencoding('utf-8') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding=utf-8 | |
import urllib | |
import urllib2 | |
import cookielib | |
import httplib | |
import json | |
import re | |
import time | |
import datetime | |
import os |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding=utf-8 | |
import urllib | |
import urllib2 | |
import cookielib | |
import httplib | |
import json | |
import re | |
import time | |
import datetime | |
import os |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object LineCounter { | |
def main(args : Array[String]) = { | |
val code_exts = Set("cc", "java", "cpp", "c", "py", "cxx", "hs", "scala", "scl") | |
def walk(f: java.io.File): Int = { | |
val list = f.listFiles() | |
var tot = 0 | |
list foreach { (x) => | |
if(x.getName contains "模版"){} | |
else if(x.isFile()) { | |
val ext = x.getName lastIndexOf('.') match { |