神一样的题目。简言之,利用手段获得测试用例的第一行,输出结果。
很显然利用wa, TLE, OLE等judge status可以获得测试用例。
因此,果断Python写一个acm提交机器人。依赖lxml库。
测试用例是The Ascii of H.

 #!/usr/env python

 import urllib2
import urllib
import cookielib
import logging
from urlparse import *
from time import sleep
from lxml import etree
import string global url, n_vol
url = "http://acm.hdu.edu.cn"
n_vol = 46
judgeStatus_xpath = "/html/body/table/tr[4]/td/div/table/tr[2]/td[3]/font" def initLog():
# os.chdir(parentDirPath)
suffix = 'hdu'
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S',
filename=__file__[:-3]+'_'+suffix+'.log',
filemode='w') def acmHdu_Login(user, password):
login_page = urljoin(url, "userloginex.php?action=login")
try:
'create cookie'
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener.addheaders = [('User-agent',\
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)')]
data = urllib.urlencode({"username":user, "userpass":password})
urllib2.install_opener(opener)
urllib2.urlopen(login_page, data) except Exception, e:
print "Login unsucceed"
print e def acmHdu_Submit(pid, lang, code):
submit_url = urljoin(url, "submit.php?action=submit")
data = urllib.urlencode({"problemid":pid, "language":lang, "usercode":code})
req = urllib2.Request(submit_url, data)
response = urllib2.urlopen(req)
content = response.read() def acmHdu_Status(user, pid, lang):
sleep(5)
status_url = urljoin(url, "status.php?first=&pid=%s&user=%s&lang=%s&status=0" % (str(pid), user, str(lang+1)))
# print status_url
content = urllib2.urlopen(status_url).read()
with open("C:\Users\hooh\Desktop\st.html", "w") as fout:
fout.write(content) def acmHdu_Status_Parse(user, pid, lang):
sleep(5)
status_url = urljoin(url, "status.php?first=&pid=%s&user=%s&lang=%s&status=0" % (str(pid), user, str(lang+1)))
# print status_url
content = urllib2.urlopen(status_url).read()
tree = etree.HTML(content)
infoList = map(
lambda ele: ele.text, tree.xpath(judgeStatus_xpath)
)
return infoList[0] if infoList else "" class constForSubmit:
can = ' ' + string.digits + string.uppercase + string.lowercase
pid = 3337
lang = 2
template = string.Template(\
'''
/* 3337 */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 char pattern[105];
int len; void init() {
len = 0;
pattern[len++] = ' ';
rep(i, 0, 10)
pattern[len++] = '0'+i;
rep(i, 0, 26)
pattern[len++] = 'A'+i;
rep(i, 0, 26)
pattern[len++] = 'a'+i;
puts(pattern);
} void WA() {
puts("Wa");
} void TLE() {
while (true);
} void OLE() {
while (true)
puts("123");
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif init(); char line[20]; gets(line);
int len = strlen(line);
int index = $index;
int th = $th; if (index >= len)
OLE(); if (pattern[th] == line[index]) {
WA();
} else {
while (true)
;
} #ifndef ONLINE_JUDGE
printf("time = %d.\\n", (int)clock());
#endif return 0;
} ''') class CFS(constForSubmit):
pass def acmHdu_Submit3337(user, pid, lang, template):
maxl = 20
varDict = dict()
cn = len(CFS.can)
ret = ""
for index in xrange(maxl):
flag = False
for th in xrange(cn):
varDict["index"] = index
varDict["th"] = th
code = template.safe_substitute(varDict)
acmHdu_Submit(pid, lang, code)
while True:
status = acmHdu_Status_Parse(user, pid, lang).strip()
if status=="Running" or status=="Queuing" or status=="Compiling":
continue
print status
if status == "Wrong Answer":
### find the correct char
ret += CFS.can[th]
flag = True
break
elif status == "Output Limit Exceeded":
### find the last char
logging.debug("Result is %s" % (ret))
return ret
elif status == "Time Limit Exceeded":
break
else:
continue
if flag:
break
logging.debug("%d: ret = %s" % (index, ret))
return ret if __name__ == "__main__":
# user = "Bombe16"
# password = "496528674"
# initLog();
# logging.debug("acm submit begin...")
# acmHdu_Login(user, password)
# acmHdu_Submit(CFS.pid, CFS.lang, CFS.code)
# acmHdu_Status(user, CFS.pid, CFS.lang)
# logging.debug("acm submit end...") user = "Bombe16"
password = ""
initLog();
logging.debug("acm submit begin...")
acmHdu_Login(user, password)
line = acmHdu_Submit3337(user, CFS.pid, CFS.lang, CFS.template)
with open("F:\Qt_prj\hdoj\data.in", "w") as fout:
fout.write(line)
logging.debug("acm submit end...")

【HDOJ】3337 Guess the number的更多相关文章

  1. 【HDOJ】1394 Minimum Inversion Number

    逆序数的性质.1. 暴力解 #include <stdio.h> #define MAXNUM 5005 int a[MAXNUM]; int main() { int n; int i, ...

  2. 【贪心】codeforces D. Minimum number of steps

    http://codeforces.com/contest/805/problem/D [思路] 要使最后的字符串不出现ab字样,贪心的从后面开始更换ab为bba,并且字符串以"abbbb. ...

  3. 【LeetCode】9、Palindrome Number(回文数)

    题目等级:Easy 题目描述: Determine whether an integer is a palindrome. An integer is a palindrome when it rea ...

  4. 【leetcode】668. Kth Smallest Number in Multiplication Table

    题目如下: 解题思路:几乎和[leetcode]719. Find K-th Smallest Pair Distance 的方法一样.只不过一个是减法一个是乘法,还有一点区别是[leetcode]7 ...

  5. 【HDOJ】3948 The Number of Palindromes

    后缀数组求不重复回文子串数目.注意dp数组. /* 3948 */ #include <iostream> #include <sstream> #include <st ...

  6. 【HDOJ】4162 Shape Number

    循环串的最小表示法. /* */ #include <iostream> #include <string> #include <map> #include < ...

  7. 【HDOJ】3509 Buge's Fibonacci Number Problem

    快速矩阵幂,系数矩阵由多个二项分布组成.第1列是(0,(a+b)^k)第2列是(0,(a+b)^(k-1),0)第3列是(0,(a+b)^(k-2),0,0)以此类推. /* 3509 */ #inc ...

  8. 【HDOJ】1018 Big Number

    数学题,还是使用log避免大数,但是不要忘记需要+1,因为0也是1位,log(100)= 2,但却是3位. #include <stdio.h> #include <math.h&g ...

  9. 【HDOJ】3006 The Number of set

    数据量这么小,果断状态压缩+dp. /* 3006 */ #include <iostream> #include <string> #include <map> ...

随机推荐

  1. Oracle存储过程学习使用

    存储过程创建语法: create or replace procedure 存储过程名(param1 in type,param2 out type) as 变量1 类型(值范围); 变量2 类型(值 ...

  2. (CodeForces 558C) CodeForces 558C

    题目链接:http://codeforces.com/problemset/problem/558/C 题意:给出n个数,让你通过下面两种操作,把它们转换为同一个数.求最少的操作数. 1.ai = a ...

  3. CruiseControl.NET : svnrevisionlabeller

    How to use svnrevisionlabeller as your labeller type in CC.NET: 1. Download ccnet.SvnRevisionLabelle ...

  4. Windows和Linux下查看Apache、MySQL、PHP版本

    # Windows查看Apache版本: 使用命令:httpd -v # Linux查看Apache版本: 使用命令:apachectl -v # Windows查看MySQL版本: 使用命令:mys ...

  5. Mysql存储引擎__笔记

    Mysql存储引擎(表类型): Mysql数据库: 通常意义上,数据库也就是数据的集合,具体到计算机上数据库可以使存储器上一些文件的集合或者一些内存 数据的内存数据的集合. Mysql数据库是开放源代 ...

  6. OpenSUSE共享网络

    因为想要使用Arduino Ethernet扩展版,想要搭建一个局域网供其使用有线,无奈路由器离我太远.遂有本文. 实验器材: 装有OpenSUSE.有线网卡.无线网卡的笔记本. 路由器一台. 实验步 ...

  7. Asp.net 图片文件防盗链介绍

    想要实现文件放盗链的功能 首先添加一个全局文件 Global.asax 在 Application_BeginRequest中我们可以判断Http报文头中的UrlReferre是否来源本站. if ( ...

  8. MVC , MVP , MVVM【转 阮一峰的网络日志】

    一.MVC MVC模式的意思是,软件可以分成三个部分. 视图(View):用户界面. 控制器(Controller):业务逻辑 模型(Model):数据保存 各部分之间的通信方式如下. View 传送 ...

  9. MySQL中SQL语句的分类

    1:数据定义语言(DDL) :创建和删除数据库(CREATE DATABASE || DROP  DATABASE):2:创建.修改.重命名.删除表(CREATE  TABLE || ALTER TA ...

  10. 修改oracle数据库为归档模式

    参考博客:http://blog.csdn.net/codesaint/article/details/1901030 Oracle分为非归档模式(NOARCHIVELOG)  和归档模式(ARCHI ...