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.
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
| 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() |
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
| 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 |
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 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 |
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
| #include <iostream> | |
| #include <algorithm> | |
| #include <cstdlib> | |
| #include <cstdio> | |
| #include <cstring> | |
| using namespace std; | |
| int sticks[64], n, len, num; | |
| bool used[64]; | |
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
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #define MAX 202 | |
| int key[MAX], t[MAX]; | |
| /* 求解置换周期 */ | |
| void get_time(int n) |
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
| try to add name to gists |
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
| 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.
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
| 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. |