Skip to content

Instantly share code, notes, and snippets.

View dodola's full-sized avatar
:octocat:
Focusing

dodola dodola

:octocat:
Focusing
View GitHub Profile
@dodola
dodola / gist:5310616
Created April 4, 2013 14:02
Android 获取系统已使用的内存
long total=Runtime.getRuntime().totalMemory();//获取系统内存总数
long free=Runtime.getRuntime().freeMemory();//获取剩余内存
long used=total-free;//获取已使用内存
@dodola
dodola / read.java
Created April 4, 2013 14:10
Android 获取数组资源中的值
Resources res=getResources();
TypedArray icons =res.obtainTypedArray(R.array.icons);
Drawable drawable1=icons.getDrawable(0);
Drawable drawable2=icons.getDrawable(1);
Drawable drawable3=icons.getDrawable(2);
@dodola
dodola / Common.c
Created May 31, 2013 10:03
ACM 常用函数
#include <stdio.h>
int getchar( void ); //读取一个字符, 一般用来去掉无用字符
char *gets( char *str ); //读取一行字符串
#include <stdlib.h>
void * malloc( size_t size ); //动态内存分配, 开辟大小为 size 的空间
void qsort( void *buf, size_t num, size_t size, int (*compare)(const void *, const void *) ); //快速排序
Sample:
int compare_ints( const void* a, const void* b )
{
@dodola
dodola / binsearch.cpp
Created June 20, 2013 08:16
二分法查找
#include<iostream>
using namespace std;
bool bin_search(int nums[],int i,int len){
int left=0,right=len-1,middle;
while(left<=right){
middle=left+((right-left)>>1);
if(i>nums[middle]){
left=middle+1;
}else if(i<nums[middle]){
@dodola
dodola / bignum.cpp
Created June 20, 2013 08:50
大数模板
#define MAXN 9999
#define DLEN 4
class BigNum {
private:
int a[1000];//可以控制大数的位数
int len; //大数长度
public:
BigNum() {len = 1;memset(a,0,sizeof(a));}
BigNum(const int);
BigNum(const char*);
@dodola
dodola / ACM学习计划
Created August 14, 2013 02:14
ACM学习计划
ACM大量习题题库
ACM大量习题题库
现在网上有许多题库,大多是可以在线评测,所以叫做Online Judge。除了USACO是为IOI准备外,其余几乎全部是大学的ACM竞赛题库。
USACO
http://ace.delos.com/usacogate
美国著名在线题库,专门为信息学竞赛选手准备
@dodola
dodola / ReadContacts.java
Created August 23, 2013 03:45
读取联系人
Cursor query = this.getContentResolver().query(ContactsContract.Data.CONTENT_URI, new String[] { ContactsContract.Data._ID, ContactsContract.CommonDataKinds.Phone.LABEL, ContactsContract.CommonDataKinds.Phone.NUMBER }, "", null, "");
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, query, new String[] { ContactsContract.CommonDataKinds.Phone.LABEL, ContactsContract.CommonDataKinds.Phone.NUMBER }, new int[] { android.R.id.text1, android.R.id.text2 }, 0);
mListView.setAdapter(adapter);
@dodola
dodola / ObserverMe.java
Created August 23, 2013 06:23
Java 观察者模式示例
import java.util.Observable;
import java.util.Observer;
/*
* Java 观察者模式示例
*/
class MyDataObservable extends Observable {
private String data;
public String getData() {
#encoding: utf-8
__author__ = 'Dodola'
from lxml.html import parse
from time import sleep,ctime
import time
import urllib.request
import threading
import contextlib
import queue
@dodola
dodola / QuickSort.java
Created September 3, 2013 06:19
算法导论·快排
public class QuickSort {
public static int partition(int[] nums, int p, int r) {
int x = nums[r];// 取最后一位作为基准
int i = p - 1;
for (int j = p; j < r; j++) {
if (nums[j] <= x) {
i++;
// 交换