# 某储备粮的“学习笔记”

by 咳嗽di小鱼

``````String filename = "path/file.txt";
File file = new File(filename);
FileInputStream fileinput = new FileInputStream(file.getAbsolutePath());
int x = fileinput.available();
byte b[] = new byte[x];
String string = new String(b);
System.out.println(string);
``````

XLib是X Window编程的基础Library, 使用时首先需要在文件头中

``````#include <X11/Xlib.h>
``````

``````// Open display
Display* display;
display = XOpenDisplay("");
if(!display){
printf("Cannot open display\n");
exit(-1);
}
``````

## Comparison-based sorting

### QuickSelect

#### 组成函数

• choose-pivot(A) 在数据中选择其中一个作为pivot
• partition(A, p) 使用A[p]作为pivot, 将A中的数据分为

• 所有小于等于pivot的数据
• pivot本身
• 所有大于pivot的数据

#### Implementation

``````void swap(int *A, int i, int j){
int temp;
temp = A[i];
A[i] = A[j];
A[j] = temp;
return;
}
``````

= =...`消极怠工消极怠工, 240拖到最后一秒算是交掉了. w/e

vector好像并不是高效率的选择, 不过随它去吧`这次的tree实在有够恶心

``````#include <vector>

int kTh(vector<int> & vals, int k){
if(k == 0){ // 如果k为0, 则取中点
k = vals.size();
k = k / 2 + k % 2;
}

vector<int> v, l ,r;
int i;
v = vals;
int c, n = 0, s = v.size(), p = v[0]; // pivot = the first

while(true){
for(i = s-1; i >= 0; i--){ // partite
c = v[i];
if(c <= p) l.push_back(c);
else if(c > p) r.push_back(c);
}
s = l.size();
if(s == k) break; // find the k'th
else if(s > k) v = l; // in left
else if(s < k) { // in right
k = k - l.size();
v = r;
}

l.clear();
r.clear();
s = v.size();
p = v[0]; // re-choose pivot
}
return p;
}
``````