神一样的题目。简言之,利用手段获得测试用例的第一行,输出结果。
很显然利用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. iOS开发——手机号,密码,邮箱,身份证号,中文判断

    目前这些方面的判断主要是用了正则表达式 手机号的判断,目前主要是长度.均是数字,支持的号段由于第三方通讯比如京东通讯,小米通讯等支持的号段挺多, 有171,170,135,147等等,所以号段限制简单 ...

  2. IOS-用动画组制作花瓣掉落效果(另附iOS动画图表)

    重要的两个方法:1.动画的数组:animations 2.启动的时间 beginTime 注意:动画组设置了持续时间(duration)可能会导致动画组里面的持续时间不管用 代码如下: #import ...

  3. 15_会话技术_Cookie

    [简述] 会话可理解为:用户打开一个浏览器,点击多个超链接,访问服务器多个Web资源,然后关闭浏览器,整个过程成为一个会话. [会话过程中我们要解决的一些问题] * 每个用户与服务器进行交互的过程中, ...

  4. OpenJudge 2810(1543) 完美立方 / Poj 1543 Perfect Cubes

    1.链接地址: http://bailian.openjudge.cn/practice/2810/ http://bailian.openjudge.cn/practice/1543/ http:/ ...

  5. CentOS7 systemctl的使用

    # 查看正在运行的服务 systemctl # 查看某个服务的状态 systemctl status httpd.service # 启动服务 systemctl start  foo.service ...

  6. Web前端新人笔记之CSS结构和层叠

    上一篇文章介绍了如何利用CSS选择器为元素应用各种丰富的样式,每个合法的文档都会生成一个结构树,了解这一点,就能根据元素的祖先.属性.兄弟等元素穿件选择器选择元素. 本篇文章将讨论3中机制之间的关系: ...

  7. sql 自定义排序

    方法一: 比如需要对SQL表中的字段NAME进行如下的排序: 张三(Z) 李四(L) 王五(W) 赵六(Z) 按照sql中的默认排序规则,根据字母顺序(a~z)排,结果为:李四  王五 赵六 张三   ...

  8. C#基础(七)——静态类与非静态类、静态成员的区别

    静态类 静态类与非静态类的重要区别在于静态类不能实例化,也就是说,不能使用 new 关键字创建静态类类型的变量.在声明一个类时使用static关键字,具有两个方面的意义:首先,它防止程序员写代码来实例 ...

  9. Apose 套打

    给web添加一个dll引用:Apose.Words 下载链接:http://yunpan.cn/cA7v6uceM6KVw  提取码 11df 在Global.asax里面的Application_S ...

  10. python AES 加密与解密

    #用aes加密,再用base64 encode def aes_encrypt(data): from Crypto.Cipher import AES import base64 key=setti ...