返回列表 发帖
回复 75# 老刘1号


    说明他用多进程或者多线程跑啊。(其中之一)
[url=][/url]

TOP

回复 76# 523066680


    按说服务器的反应速度也就那样,个人觉得多线程反而会拉慢速度(没有测试)
嘿嘿,这是逼我改进代码啊

TOP

本帖最后由 523066680 于 2017-7-19 15:40 编辑

回复 77# 老刘1号


    不是的,我说说中午之前我的方案吧,
两个进程同时跑,一个随机数做划分,一个是取中值做划分。发现确实比codegay快了。
现在范围变了发现两个进程都慢,还是有优化方向

以及刚才我的后台在跑迅雷,下载 KOF14

现在看来主要还是网络因素,两个进程对比Codegay,勉强持平
codegay    19038 + 11
vic2       1569 + 7
老刘       920 + 0
vic3       0 + 0
e          0 + 0
repeat
codegay    19038 + 11
vic2       1569 + 9
老刘       920 + 0
vic3       0 + 0
e          0 + 0
repeat
codegay    19038 + 11
vic2       1569 + 11
老刘       920 + 0
vic3       0 + 0
e          0 + 0COPY
[url=][/url]

TOP

本帖最后由 老刘1号 于 2017-7-19 15:37 编辑

回复 78# 523066680


    我是纯中心划分
还是感觉多线程会拉慢速率(会挑空测试下)……
确实可以改进

迅雷下载还玩这个666

TOP

网速当然非常影响了。

另外异常处理很重要,不然不能长时间运行。
去学去写去用才有进步。安装python3代码存为xx.py 双击运行或右键用IDLE打开按F5运行

TOP

回复 80# codegay


    都快2w了...

TOP

看样子站长的racket代码要来了
去学去写去用才有进步。安装python3代码存为xx.py 双击运行或右键用IDLE打开按F5运行

TOP

是谁在注册大量小号呢
去学去写去用才有进步。安装python3代码存为xx.py 双击运行或右键用IDLE打开按F5运行

TOP

一觉起来……还在刷

TOP

本帖最后由 TSCAN 于 2017-7-20 10:16 编辑
#lang racket
(require net/http-client json)
(define (reg username)
  (define-values
    (a b c)
    (http-sendrecv "bbaass.tk"
                 "http://bbaass.tk/math/"
                 #:method "POST"
                 #:headers (list "Content-Type: application/x-www-form-urlencoded")
                 #:data (string-append "send=reg&username=" username)))
  (port->string c))
(define ((send-answer username) ans)
  (define-values
    (a b c)
    (http-sendrecv "bbaass.tk"
                 "http://bbaass.tk/math/"
                 #:method "POST"
                 #:headers (list "Content-Type: application/x-www-form-urlencoded")
                 #:data
                 (string-append "send=Answer&username=" username "&"
                                "math=" (number->string ans) "&")
                                ))
  c
  )
(define (try-once min max)
  (define (mid x y) (floor (/ (+ x y) 2)))
  (define first-time
                      (read-json ((send-answer "racket")
                      (mid min max)))
                      )
  (define token (hash-ref first-time 'tokens))
  (define first-re (hash-ref first-time 're))
  (define (token-changed? t)
    (not (string=? token t)))
  (define (loop min max exit)
    (printf "min :~a,max :~a\n" min max)
    (define this-time (read-json ((send-answer "racket") (mid min max))))
    (define this-token (hash-ref this-time 'tokens))
    (define this-re (hash-ref this-time 're))
    (when (string=? this-re "=") (exit (printf "succeed.\n")))
    (when (token-changed? this-token) (exit (void)))
    (match this-re
      ["<" (loop (mid min max) max exit)]
      [">" (loop min (mid min max) exit)]))
  (call/ec
   (lambda (exit) (loop min max exit)))
  )
(define (repl) (try-once 0 10000) (repl))
(repl)COPY
racket代码,有点慢,注意先用reg函数注册。

更新的代码,速度更快:
#lang racket
(require net/http-client json racket/unsafe/ops)
(define (reg username)
  (define-values
    (a b c)
    (http-sendrecv "bbaass.tk"
                   "http://bbaass.tk/math/"
                   #:method "POST"
                   #:headers (list "Content-Type: application/x-www-form-urlencoded")
                   #:data (string-append "send=reg&username=" username)))
  (port->string c))
(define-syntax-rule (send-answer connection ans)
  (let-values
      [[(a b c)
        (http-conn-sendrecv! connection
                             "http://bbaass.tk/math/"
                             #:method "POST"
                             #:headers (list "Content-Type: application/x-www-form-urlencoded")
                             #:data
                             (string-append "send=Answer&username=racket&"
                                            "math=" (number->string ans) "&")
                             )]]
    c
    ))
;;Update : No function call here
(define-syntax-rule (mid x y) (if (= 1 (- y x))
                                  y (unsafe-fxquotient (unsafe-fx+ x y) 2)))
(define (try-once)
  (define min 0)
  (define max 10000)
  (define next (mid min max))
  ;;Update : A bug has been fixed.
  (define http-connector (http-conn-open "bbaass.tk" #:auto-reconnect? #t))
  (define first-time
    (read-json (send-answer http-connector
                            (mid min max)))
    )
  (define token (hash-ref first-time 'tokens))
  (define first-re (hash-ref first-time 're))
  (define (token-changed? t)
    (not (string=? token t)))
  
  (define (loop min max)
    (printf "min :~a,max :~a\n" min max)
    (define next (mid min max))
    (define this-time (read-json (send-answer http-connector next)))
    (define this-token (hash-ref this-time 'tokens))
    (define this-re (hash-ref this-time 're))
    (cond
      [(string=? this-re "=") (begin (printf "succeed.\n")
                                     (http-conn-close! http-connector)
                                     )]
      [(token-changed? this-token)  (http-conn-close! http-connector)]
      [(string=? this-re "<") (loop next max)]
      [(string=? this-re ">") (loop min next)]
      
      ))
  ;;Update: Because of tail call optimization, we don't need call/cc or call/ec
  (match first-re
    ["<" (loop next max)]
    [">" (loop min next)]
    [_ (begin (printf "succeed.\n")
              (http-conn-close! http-connector)
              )]
    )
  )
  
(define (repl) (try-once) (repl))
(repl)COPY
3

评分人数

TOP

回复 83# codegay


    以加屏蔽 UA策略封禁......

TOP

本帖最后由 老刘1号 于 2017-7-20 18:08 编辑

新版:
1、递归优化为循环,优化算法。
2、强大的错误处理,服务器挂掉了都还会运行等待恢复。
3、开始检测tokens的值的变化。
其它:
为防止利用,做了简单加密(使用乱码兄的加密代码)~
决定开源,代码无法运行,需要改UA
不过算法是完整的
VBS
Const [宿主] = "CSCRIPT.EXE" 'WSCRIPT
If Not UCase(Right(WScript.FullName,11)) = UCase([宿主]) Then
Dim Args,Arg
For Each Arg in Wscript.Arguments
Args=Args&Chr(&H20)&Chr(&H22)&Arg&Chr(&H22)
Next
CreateObject("Wscript.Shell").Run _
[宿主]&Chr(&H20)&Chr(&H22)&WScript.ScriptFullName&Chr(&H22)&Args
WScript.Quit
End If
on error resume next
If MsgBox("是否查看原贴?",1) = 1 Then CreateObject("Wscript.Shell").run "http://www.bathome.net/thread-44616-1-1.html"
With CreateObject("MSXML2.XMLHTTP")
.Open "POST", "http://bbaass.tk/math/", False
.setRequestHeader "CONTENT-TYPE","application/x-www-form-urlencoded"
.Send "send=reg&username=老刘"
End With
dim tokens,[大鱼小鱼或等鱼?],[Arr返回的数据]
High = 10001
Low = -1
Do
Do
Mid_=(High+Low)\2
[Arr返回的数据] = Math(Mid_)
[大鱼小鱼或等鱼?] = [Arr返回的数据](0)
if tokens<>[Arr返回的数据](1) then
If [大鱼小鱼或等鱼?] = "=" then
wscript.echo "Win!The number is "&Mid_
Else
Wscript.echo "Tokens is change"
End if
tokens=[Arr返回的数据](1)
High = 10001
Low = -1
Exit do
Else
Select Case [大鱼小鱼或等鱼?]
Case ">"
WScript.Echo ">,so try "&Low&","&Mid_
High = Mid_
Case "<"
WScript.Echo "<,so try "&Mid_&","&High
Low = Mid_
End Select
End if
Loop
Loop
Function Math(num)
dim [返回数据]
With CreateObject("MSXML2.XMLHTTP")
.Open "POST","http://bbaass.tk/math/", False
.setRequestHeader "CONTENT-TYPE","application/x-www-form-urlencoded"
.send "send=Answer&math=" & num & "&username=老刘"
[返回数据] = .responseText
Math = Split(Split(Split([返回数据],",")(2),"""")(3) & " "&Split([返回数据],"""")(13)," ")
End With
End FunctionCOPY

TOP

本帖最后由 codegay 于 2017-7-20 02:17 编辑

来啊。继续挂机赛跑啊。不然不能发现代码中的一些小问题,改进的动力太也不大。
去学去写去用才有进步。安装python3代码存为xx.py 双击运行或右键用IDLE打开按F5运行

TOP

可以重置我的数据,从头开始。
去学去写去用才有进步。安装python3代码存为xx.py 双击运行或右键用IDLE打开按F5运行

TOP

本帖最后由 codegay 于 2017-7-20 07:11 编辑

这是nim版的程序,边摸边学,直到前几天写好的。这两天只作了小细节上修改。


编译命令:
nim c -d:release -r "c:\Users\root\Desktop\xx.nim"COPY
import httpclient
import strutils
import json
import math
import os
import encodings
const chrome = "Chrome/60.0.3088.3"
let apiurl = "http://bbaass.tk/math/"
var name = "codegay"
var client: HttpClient
var head = { "Content-Type": "application/x-www-form-urlencoded" ,
            "User-Agent": chrome,  "X-Requested-With": "XMLHttpRequest"}
proc reg(): int {.discardable.} =
    var client = newHttpClient()
    try:
        echo client.postContent(apiurl,
        multipart=newMultipartData({"send":"reg","username":name}))
    except:
        result = 0
    finally:
        client.close()
proc showuser(): int {.discardable.} =
    var client = newHttpClient()
    try:
        echo client.postContent(apiurl,
        multipart=newMultipartData({"send":"user", "username":name}))
        result = 1
    except:
        echo convert(getCurrentExceptionMsg(),"gb2312","utf8")
        result = 0
    finally:
        client.close()
proc answer(min=0, max=10000): string {.discardable.} =
    var min = min
    var max = max
    var answering:bool = true
    var counter = 1
    var token = ""
    var code:HttpCode = Http100
    var body = ""
    while answering:
        client = newHttpClient(chrome)
        client.headers = newHttpHeaders(head)
        var math:int = int(round((min+max)/2))
        var bodydata = "send=Answer&username=$1&math=$2" % [name,$math]
        try:
            var res = client.post(apiurl, body=bodydata)
            code = res.code
            body = res.body
            echo "HTTP:$1    counter:$2    math:$3" % [$code,$counter,$math]
            if code.is2xx():
                echo body
                try:
                    var jsonre:JsonNode = parseJson(body)
                    var re = jsonre["re"].getstr()
                    var retoken = jsonre["tokens"].getstr()
                    case re:
                        of "=":
                            answering = false
                            token = ""
                        of  ">":
                            max = math
                        of  "<":
                            min = math
                    if (min >= max):
                        echo "min >= max"
                        answering = false
                        break
                    if token != retoken and token != "":
                        echo "token!"
                        break
                    token = retoken
                except:
                    echo "解析json错误!"
            elif code == Http500:
                reg()
                echo "500"
            else:
                echo "else"
        except:
            echo convert(getCurrentExceptionMsg(),"gb2312","utf8")
            break
        finally:
            counter += 1
            client.close()
reg()
showuser()
while true:
    discard answer()COPY
1

评分人数

去学去写去用才有进步。安装python3代码存为xx.py 双击运行或右键用IDLE打开按F5运行

TOP

返回列表