Skip to content

Instantly share code, notes, and snippets.

View fotile96's full-sized avatar

fotile96

  • Tsinghua University, IIIS
  • Hangzhou
View GitHub Profile
@fotile96
fotile96 / gist:4b617d65922e648a05c48923ada400ed
Created February 7, 2025 04:59
yet another quick selection problem by r1
帮我用C++解决下面的问题:有n个double pair (a[i], b[i]),其中保证b[i]都是严格正的,我们希望首先将它们按a升序排列,并记排序后的b数组的部分和(partial sum)为B。容易看到B也是一个严格单调上升的序列。给定某个x,我们希望找到最大的i使得B[i]<=x。
为了得到O(n)而非O(nlogn)的总时间复杂度的解法,你可能可以先考虑如何实现下面一般的算法,它总体上类似于随机化的快速选择算法(quick selection algorithm),假设输入为一列n个具有全序关系的元素,且已经被random shuffle过,每次挑出一个pivot元素,在线性时间内在当前递归子区间内就地将元素移动成,在pivot元素左边的元素都小于pivot,在它右边的元素都大于它。与经典的快速选择算法的区别在于,我们希望支持传入一个回调函数来判断应该在pivot元素的哪一侧继续递归处理,而非通常的通过事先固定的某个名次k来判断。
最初的问题应当可以通过设计一个合适的callback判断函数,并调用这个快速选择算法变体来求解。不过你不需要非常严格地模块化地实现整个程序,把这个具体的callback hardcode在递归函数体里也是可以接受的。
CoT
=====
@fotile96
fotile96 / unix_socket_request.sh
Created January 17, 2024 16:07 — forked from nuxlli/unix_socket_request.sh
Examples of http request in unix domain socket with shell, using socat, netcat or curl
#!/bin/bash
# References
# http://www.computerhope.com/unix/nc.htm#03
# https://github.com/daniloegea/netcat
# http://unix.stackexchange.com/questions/26715/how-can-i-communicate-with-a-unix-domain-socket-via-the-shell-on-debian-squeeze
# http://unix.stackexchange.com/questions/33924/write-inside-a-socket-open-by-another-process-in-linux/33982#33982
# http://www.linuxjournal.com/content/more-using-bashs-built-devtcp-file-tcpip
# http://www.dest-unreach.org/socat/
# http://stuff.mit.edu/afs/sipb/machine/penguin-lust/src/socat-1.7.1.2/EXAMPLES
// ==UserScript==
// @name CowTransfer Bypass Email Check
// @version 0.1
// @description CowTransfer Bypass Email Check
// @match https://cowtransfer.com/*
// @require http://jpillora.com/xhook/dist/xhook.js
// ==/UserScript==
xhook.after(function(request, response) {
if(request.url.indexOf('login_email_white_list') != -1) {
@fotile96
fotile96 / oauth.js
Last active February 15, 2020 14:49
auth proxy worker source code
addEventListener('fetch', event => {
let resp = new Response("", {
status: 404,
});
let request = event.request;
let url = new URL(request.url);
if (request.method == "POST" && url.pathname == "/sharepoint")
resp = sharepoint_login(request);
event.respondWith(resp);
@fotile96
fotile96 / README.txt
Created February 15, 2020 13:17
one line configure guideline
在登录状态下打开 https://<TENANT>.sharepoint.com/sites/<SITE>/_api/v2.0/drives,把@odata.id复制到root_url,url最后那一段复制到drive_id
@fotile96
fotile96 / rclone.conf
Created February 15, 2020 13:10
sample rclone config
[SAMPLE]
type = onedrive
token = {"access_token":"foo","token_type":"headers","refresh_token":"{\"username\":\"<YOUR USERNAME>\",\"password\":\"<YOUR PASSWORD>\",\"tenant\":\"<YOUR TENANT NAME>.sharepoint.com\",\"site_url\":\"https://<YOUR TENANT NAME>.sharepoint.com/sites/<YOUR SITE NAME>\"}","expiry":"1970-02-15T08:47:29.993180336Z"}
drive_id = <SEE THE GUIDE>
drive_type = sharepoint
chunk_size = 20M
oauth_endpoint = <BETTER TO SET UP ONE ON YOUR OWN, OR USE https://oauth.1145.eu/sharepoint>
root_url = https://<TENANT>.sharepoint.com/sites/<SITE>/_api/v2.0/drives/<DRIVE_ID>
root_url_v1 = https://<TENANT>.sharepoint.com/sites/<SITE>/_api
#!/usr/bin/env python3
# coding=utf8
import torrent_parser
import argparse
import sys
from dataclasses import dataclass
from hashlib import sha1
import os
import random
#! /usr/bin/env python3
import sqlite3
import taglib
import sys
pathroot = {
'b:': '/Volumes/Transcend/Music Library'
}
conn = sqlite3.connect('usrlocal_media.db')
(by lydrainbowcat)
题意:
给定N个整数a1,a2...an,求1~n的一个排列p1~pn,最大化 abs(abs(abs(abs(a[p1]-a[p2])-a[p3])-a[p4])......-a[pn])。
N<=200, |ai|<=1000
解法:
首先,所有<=0的ai放在最后,可以全部利用起来,使答案不断变大。
于是只需考虑正的ai。找到其中最大的,放在最后,问题变为对于剩余的数做最小化的上述问题。
最小化就比较好做了,相当于把数分成两堆,使得他们的和尽量接近,可以用背包求解。
@fotile96
fotile96 / s1_script
Last active June 29, 2016 15:24 — forked from zxc111/s1_script
s1挂机脚本
# -*- encoding: utf8 -*-
import urllib2
import urllib
from cookielib import CookieJar
import pdb
import time
def check_process():
import subprocess
import sys