神一样的题目。简言之,利用手段获得测试用例的第一行,输出结果。
很显然利用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. 【html】【20】高级篇--轮播图[聚焦]

    下载: http://sc.chinaz.com/jiaoben/151204445580.htm 效果: html <!doctype html> <html> <he ...

  2. .Net规则引擎Biztalk,Workflow和CKRule的比较

    微软的规则引擎   很多朋友会问,.Net平台有没有规则引擎?像Java就有很多的规则引擎,Drools,ILog都做得非常好,但.Net好像还没有哦.很多知道规则引擎,但不知道.Net的朋友都烦这个 ...

  3. mybatis关联查询

    场景:一个人有多个手机号,一个手机号对应一个人 CREATE TABLE test.mobile ( mid INT NOT NULL auto_increment, tel ), pid INT, ...

  4. JavaScript基础-对象<2>

    2.浏览器环境提供对象 (1) document对象 doucument对象属性: title:文本标题.doucument.title="Welcome"; lastModifi ...

  5. Windows下lex 与 yacc的使用

     Windows下lex 与 yacc的使用 首先 下载下载flex和bison.网址是http://pan.baidu.com/s/1dDlfiW5 选择下载就好了,下载后解压到你电脑中的任一盘中. ...

  6. C++(指针)

    指针在编程中有时很重要的作用 我们可以用它完成一些看似不可能完成的任务 #include<iostream>using namespace std;void square(int *n){ ...

  7. WIX Custom Action (immediate, deffered, rollback)

    Following content is directly reprinted from From MSI to WiX, Part 19 - The Art of Custom Action, Pa ...

  8. POJ 1276 Cash Machine -- 动态规划(背包问题)

    题目地址:http://poj.org/problem?id=1276 Description A Bank plans to install a machine for cash withdrawa ...

  9. 第30条:用enum代替int常量

    在java1.5之前,表示枚举类型的常用模式是声明一组具名的int常量,每个类型成员一个常量: public static final int APPLE_FUJI = 0; public stati ...

  10. 最近用到的Linux常用命令总结

    最近用到的Linux常用命令总结 - ls :显示当前目录文件信息 `ls -a -l` - cd :目录跳转 cd .. 上级目录 cd ~ home目录 cd - 最近目录 - cat :在屏幕上 ...