Skip to content

Instantly share code, notes, and snippets.

def evaluate(pages,border, avg):
D =0
for i in range(len(border)):
d = sum(pages[border[i-1][0]:border[i][0]]) - avg
D += d**2
return D
def DFS(k, m, pages,solutions, border,branch=-1):
import pdb
pdb.set_trace()
@liuyuuan
liuyuuan / books1Dfs.py
Created September 4, 2012 04:09
BOOKS1 unfinished...
def evaluate(pages,solution, avg):
D =0
for i in range(len(solution)):
d = sum(pages[solution[i-1]:solution[i]]) - avg
D += d**2
return D
def DFS(pages, k, m):
avg = sum(pages)/m
total =0
@liuyuuan
liuyuuan / books1.py
Created September 3, 2012 12:41
spoj 43, WA
import sys
tests = input()
while tests>0:
line = sys.stdin.readline()
info = [int(elem) for elem in line.split() if elem.isdigit()]
line = sys.stdin.readline()
pages = [int(elem) for elem in line.split() if elem.isdigit()]
su = sum(pages)
border=[]
count = 0
@liuyuuan
liuyuuan / Hint.md
Created August 28, 2012 10:15 — forked from yuvipanda/Hint.md
Insertion Sort Solutions (InterviewStreet CodeSprint Fall 2011)

The answer is the number of inversions in the array, which is the number of pairs i,j such that i < j and a[i] > a[j]. Counting this is a fairly classical problem with many solutions such as using data structures such as Balanced Trees or Binary Indexed Trees. Another particularly elegant solution involves modifying merge sort to count the number of inversions when merging the two sorted halves in the algorithm.

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
using namespace std;
int sticks[64], n, len, num;
bool used[64];
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 202
int key[MAX], t[MAX];
/* 求解置换周期 */
void get_time(int n)
@liuyuuan
liuyuuan / gist:3486636
Created August 27, 2012 08:15
something
try to add name to gists
try to add name to gists

Defination of the System Load Value: Basically, load average is the amount of traffic to your CPU(s) over the past 1, 5, and 15 minutes. Generally you want this number to be below the number of CPU(s)/cores you have. 1.0 on a single core machine means it's using the CPU to it's maximum, and anything above that means things are getting queued.

The fglrx shipped with Precise has some compatility issues
with the kernel 3.2.0-29, which can cause a freeze when
shutting down, everything stops on the plymouth screen.
Replace either of them can solve this problem.