Skip to content

Instantly share code, notes, and snippets.

View luangong's full-sized avatar

Luan Gong luangong

View GitHub Profile
@luangong
luangong / main.dart
Last active March 10, 2024 14:54
CupertinoSelectFormFieldRow
import 'package:flutter/cupertino.dart';
void main() => runApp(const MyApp());
enum Direction {
up('UP'), down('DOWN'), left('LEFT'), right('RIGHT');
final String title;
const Direction(this.title);
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import codecs
import regex
import sys
def join_cjk(s):
cjk = r'([\p{CJK Unified Ideographs}\p{Halfwidth and Fullwidth Forms}])'
pattern = cjk + r'\n *' + cjk
@luangong
luangong / min_abs.cc
Last active February 6, 2017 22:35
陈利人老师微博面试编程题:一个有序数组(从小到大排列),数组中的数据有正有负,求这个数组中的最小绝对值。微博地址:http://weibo.com/1915548291/zgH8XdILh 解决思路:二分查找。注意边界情况的处理
/**
* 陈利人老师微博面试编程题:一个有序数组(从小到大排列),数组中的数据有正有负,
* 求这个数组中的最小绝对值。
*
* Sample Input
*
* -4 -2 -1 2 3 5
* -2 0 3 5 8
* -8 -6 -3 -2 1
*
@luangong
luangong / connected_components.cc
Last active February 3, 2017 10:07
求由 0 和 1 构成的矩阵中连通的 1 的矩形块的个数
/*
* 问题:给定一个由 0 和 1 组成的二维数组,求连通分量的个数。
*
* 思路:可以把该二维数组看成是一个图,1 代表结点,上下左右相邻的 1 表示
* 结点之间相连,然后用 DFS 或 BFS 遍历该图,就可以得到连通分量的个数。
*/
#include <iostream>
#include <vector>
@luangong
luangong / median.cc
Created September 26, 2012 04:47
数据流的中值:设计和实现一种数据结构能支持两种操作,Insert(value) 和 GetMedian()。http://weibo.com/1915548291/yDD0Cmbg1
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
template<typename T>
class MyContainer {
public:
void insert(const T& val);
@luangong
luangong / maximum_subtree.cc
Last active February 3, 2017 09:39
求二叉树的最大子树
#include <iostream>
#include <limits>
struct Node {
long data;
Node *lchild;
Node *rchild;
};
@luangong
luangong / evaluate_expression.cc
Created August 24, 2012 14:05
简单表达式求值。数字为个位数,可能为负数,运算符包括 +, -, *, /, (, ) 这几种
/*
* 表达式求值(http://www.bianchengla.com/course/ds/practise/problem?id=1322)
*
* 时间限制:1000 ms 内存限制:65536 KB
*
* 描述
*
* 给一些包含加减号和小括号的表达式,求出该表达式的值。表达式中的数值均为
* 绝对值小于 10 的整数。
*
/*
* 二十四点游戏
*
* 时间限制:1000 ms 内存限制:8196 KB
*
* 描述
*
* 算二十四点是个很好玩的扑克牌游戏,给 4 张的 A 至 K 的扑克牌,分别代表 1~13,
* 随意组合这四张牌,只使用 +, -, *, / 的四则运算,不使用其他运符和括号。
* 请判断给定的四张牌是否可以算出二十四点。
@luangong
luangong / inversions.py
Created June 16, 2012 16:01
A Python program that calculates the inversions of a given array using the divide-and-conquer method.
#! /usr/bin/python
# coding: UTF-8
import sys
def main():
a = []
for line in sys.stdin:
a.append(int(line))
print count_inversions(a, 0, len(a) - 1)