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
| 帮我用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 | |
| ===== |
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
| #!/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 |
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
| // ==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) { |
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
| 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); |
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
| 在登录状态下打开 https://<TENANT>.sharepoint.com/sites/<SITE>/_api/v2.0/drives,把@odata.id复制到root_url,url最后那一段复制到drive_id |
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
| [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 |
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
| #!/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 |
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
| #! /usr/bin/env python3 | |
| import sqlite3 | |
| import taglib | |
| import sys | |
| pathroot = { | |
| 'b:': '/Volumes/Transcend/Music Library' | |
| } | |
| conn = sqlite3.connect('usrlocal_media.db') |
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
| (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。找到其中最大的,放在最后,问题变为对于剩余的数做最小化的上述问题。 | |
| 最小化就比较好做了,相当于把数分成两堆,使得他们的和尽量接近,可以用背包求解。 |
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
| # -*- encoding: utf8 -*- | |
| import urllib2 | |
| import urllib | |
| from cookielib import CookieJar | |
| import pdb | |
| import time | |
| def check_process(): | |
| import subprocess | |
| import sys |