找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
楼主: bbaa

[数值计算] 【Warning:此贴已经过气】【挑战】用任何语言在猜数游戏作弊

[复制链接]
 楼主| 发表于 2017-7-23 14:14:32 | 显示全部楼层
本帖最后由 bbaa 于 2017-7-23 14:21 编辑

回复 134# 523066680


    勉强看懂...一点点.............
曲线图AJAX更新已经发布
点击打开

前端使用类库
chart.js
jquery.....
后端用https://git.oschina.net/kenvix/Tieba-Cloud-Sign的数据库操作类[我太懒了.....][之前还用文件存储来着?]
信息收集
  1.         /* Model:曲线图变化速度信息收集模块 Start */
  2.                 $dataqx=json_decode(str_replace("\\\u","\u",option::get("bbaa_math_text")),true);
  3.                 $json=Json_decode(getsql(),true);
  4.                 /* 如果在主项中已经没有这个用户,在数据中删除掉 */
  5.                         foreach($dataqx as $zh=>$va) {
  6.                                 if(empty($json["Username"][$zh])) {
  7.                                         Unset($dataqx[$zh]);
  8.                                 }
  9.                         }
  10.                 /* 如果在主项中已经没有这个用户,在数据中删除掉 End*/
  11.                 //$times=time()-(int)$change["change"]["fminute"]["last"]["Timestamp"];
  12.                 foreach ($change["change"]["minute"]["done"]["user"] as $key=>$value) {
  13.                         If ($qst) {
  14.                                 //unset($dataqx[$key]["Timestamp"]);
  15.                                 if((int)Count($dataqx[$key]["data"])<12) {
  16.                                         $dataqx[$key]["data"][Count($dataqx[$key]["data"])]=$value;
  17.                                 } else {
  18.                                         /* 对于data满12的一个处理 {*/
  19.                                                 $temp=Array(); //对foreach的处理机制做出应对
  20.                                                 foreach ($dataqx[$key]["data"] as $keyt=>$val) {
  21.                                                         if ((int)$keyt>0&&(int)$keyt<12) {
  22.                                                                 $temp[$key]["data"][Count($temp[$key]["data"])]=$val;
  23.                                                         }
  24.                                                 }
  25.                                                 Unset($dataqx[$key]["data"]);
  26.                                                 $dataqx[$key]["data"]=$temp[$key]["data"]; //合并
  27.                                                 Unset($temp);
  28.                                         /* 对于data满12的一个处理 }*/
  29.                                         $dataqx[$key]["data"][Count($dataqx[$key]["data"])]=$value;
  30.                                         unset ($count);
  31.                                 }
  32.                         }
  33.                 }
  34.         /* Model:曲线图变化速度信息收集模块 End *
复制代码
  1. case "getlinedata":
  2.                         $json=Json_decode(getsql(),true);
  3.                        
  4.                         $Timestamp=$change_tmp["change"]["minute"]["last"]["Timestamp"];
  5.                         $if_date=date("H:i",$Timestamp);
  6.                         if($if_date==$_POST["Timestamp"]) {die(json_encode(array("Code"=>400)));}
  7.                         unset($change_tmp);
  8.                         $change=json_decode(str_replace("\\\u","\u",option::get("bbaa_math_text")),true);
  9.                         $tmp=Array();
  10.                         foreach($_POST["list"] as $value) {
  11.                                 $tmp[$value]=$change[$value]["data"][count($change[$value]["data"])-1];
  12.                         }
  13.                         die(json_encode(array("Code"=>200,"data"=>$tmp,"Timestamp"=>$if_date)));
  14.                         unset($tmp);
  15.                 break;
复制代码
后端更新频率一分钟一次
前端get频率10秒一次

点击打开
外链图片展示
因alpha(透明)通道等原因背景为黑

评分

参与人数 2技术 +2 收起 理由
老刘1号 + 1 6
523066680 + 1 厉害了

查看全部评分

 楼主| 发表于 2017-7-24 17:42:30 | 显示全部楼层
朋友推荐我听这首歌
拿出来祸害人类
http://music.163.com/#/m/song?id=4466775&userid=379014753
发表于 2017-7-25 09:35:21 | 显示全部楼层
我在这个帖子下看到各种语言写的程序,被夸到飞起来,那个6啊。
坐等新的突破
发表于 2017-7-28 10:03:48 | 显示全部楼层
多线程,实测速度能稳定在 20/min 以上(由网络环境决定)
Java 代码
  1. import com.google.gson.Gson;
  2. import okhttp3.*;

  3. import java.io.IOException;

  4. public class Main {

  5.     private static final OkHttpClient client = new OkHttpClient();
  6.     private volatile static int calls = 0;

  7.     private static int min = -1;
  8.     private static int max = 10001;
  9.     private static String tokens = null;
  10.     private static boolean finished = false;
  11.     private static int times = 0;

  12.     static {
  13.         client.dispatcher().setMaxRequests(Integer.MAX_VALUE);
  14.         client.dispatcher().setMaxRequestsPerHost(Integer.MAX_VALUE);
  15.     }

  16.     public static void main(String[] args) {
  17.         int next;
  18.         int add;
  19.         long start = System.nanoTime();
  20.         while (true) {
  21.             if (calls != 0) continue;
  22.             if (finished) {
  23.                 System.out.println(String.format("%d 次 %fs", times, (System.nanoTime() - start) / 1000000000d));
  24.                 start = System.nanoTime();
  25.                 times = 0;
  26.                 finished = false;
  27.             }
  28.             if (max - min < 10) {
  29.                 for (int i = min + 1; i < max; i++) {
  30.                     guessAsync(i);
  31.                 }
  32.                 continue;
  33.             }
  34.             next = min;
  35.             add = (max - min) / 4;
  36.             for (int i = 0; i < 3; i++) {
  37.                 guessAsync(next += add);
  38.             }
  39.         }
  40.     }

  41.     private static void guessAsync(int num) {
  42.         FormBody body = new FormBody.Builder()
  43.                 .add("send", "Answer")
  44.                 .add("math", String.valueOf(num))
  45.                 .add("username", "Scallop")
  46.                 .build();
  47.         Request request = new Request.Builder().url("http://bbaass.tk/math/").post(body).build();
  48.         client.newCall(request).enqueue(new Callback() {
  49.             @Override
  50.             public void onFailure(Call call, IOException e) {
  51.                 e.printStackTrace();
  52.                 calls--;
  53.             }

  54.             @Override
  55.             public void onResponse(Call call, Response response) throws IOException {
  56.                 synchronized (client) {
  57.                     try {
  58.                         if (finished) {
  59.                             response.close();
  60.                             calls--;
  61.                             return;
  62.                         }
  63.                         if (!response.isSuccessful()) {
  64.                             response.close();
  65.                             System.out.println("---故障---");
  66.                             calls--;
  67.                             return;
  68.                         }
  69.                         BBAAResponse result = new Gson().fromJson(response.body().string(), BBAAResponse.class);
  70.                         response.close();
  71.                         String re = result.re;
  72.                         boolean reset = !result.tokens.equals(tokens) && !re.equals("=");
  73.                         if (reset) {
  74.                             if (!result.winer.equals("Scallop")) {
  75.                                 System.out.println(String.format("---重置 by %s---", result.winer));
  76.                             }
  77.                             tokens = result.tokens;
  78.                         }
  79.                         switch (result.re) {
  80.                             case "<":
  81.                                 if (min < num) min = num;
  82.                                 if (reset) max = 10001;
  83.                                 break;
  84.                             case "=":
  85.                                 min = -1;
  86.                                 max = 10001;
  87.                                 finished = true;
  88.                                 break;
  89.                             case ">":
  90.                                 if (max > num) max = num;
  91.                                 if (reset) min = -1;
  92.                         }
  93.                     } catch (Exception e) {
  94.                         e.printStackTrace();
  95.                     }
  96.                     calls--;
  97.                 }
  98.             }
  99.         });
  100.         calls++;
  101.         times++;
  102.     }

  103.     private static class BBAAResponse {
  104.         int code;
  105.         String re;
  106.         String tokens;
  107.         String winer;
  108.     }
  109. }
复制代码
发表于 2017-7-28 14:23:49 | 显示全部楼层
本帖最后由 523066680 于 2017-7-29 08:28 编辑



截图中 adad 的速度是S发布的代码在另一台电脑上运行的结果(当时vic3的程序暂停了)


情况就是这么个情况。

          评分君好像很激动……
                       |

评分

参与人数 1技术 +1 收起 理由
codegay + 1 继续晒数据啊。

查看全部评分

发表于 2017-7-29 07:16:16 | 显示全部楼层
回复 140# 523066680


    那么C语言版能跑出惊人的数据?
发表于 2018-12-25 20:39:59 | 显示全部楼层
本帖最后由 523066680 于 2018-12-25 21:05 编辑

回复 141# codegay

    那个时候最大的问题是我们这一边的代码几乎都没有加 keep_alive,导致提交速度慢了好多倍。
对方提供的java程序跑起来速度翻倍怎么想都有点夸张,特别是看到源码后发现他们的算法也还有优化空间(bulls and cows那个游戏),
当时不懂网络就错误地怀疑是程序性能啦(java的网络库也确实快)。

到了数独游戏,C语言+DLX算法是真的快。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 05:42 , Processed in 0.017947 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表