-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
425 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include "../Judger.hpp" | ||
#include "../Network.hpp" | ||
#include "../OJAPI.hpp" | ||
#include "../OJAdapter.hpp" | ||
#include "../Scanner.hpp" | ||
#include "../Timer.hpp" | ||
#include <iostream> | ||
static FT readImpl(const std::string& str, | ||
const std::string& bak) { | ||
{ | ||
std::regex pattern("texttt\\{([.0-9]+)" + bak + | ||
"\\}", | ||
regexFlag4Search); | ||
std::smatch match; | ||
std::regex_search(str, match, pattern); | ||
if(match.size() == 2) | ||
return scan<FT>(match[1].str()); | ||
} | ||
{ | ||
std::regex pattern("([.0-9]+)\\\\texttt\\{" + | ||
bak + "\\}", | ||
regexFlag4Search); | ||
std::smatch match; | ||
std::regex_search(str, match, pattern); | ||
if(match.size() == 2) | ||
return scan<FT>(match[1].str()); | ||
} | ||
return 0; | ||
} | ||
static bool readOpt(Option& opt, | ||
const std::string& str) { | ||
std::string title; | ||
{ | ||
std::regex pattern("<h1 class=\"page-header " | ||
"text-center\">([ " | ||
"\\S]+)</h1>", | ||
regexFlag4Search); | ||
std::smatch match; | ||
std::regex_search(str, match, pattern); | ||
if(match.size() == 2) | ||
title = "UOJ" + match[1].str(); | ||
else | ||
return false; | ||
} | ||
FT maxTime = readImpl(str, "s"); | ||
int64_t maxMem = readImpl(str, "MB"); | ||
if(maxTime == 0 || maxMem == 0) | ||
return false; | ||
std::cout << "\033[34m"; | ||
std::cout << "Title:UOJ" << title << std::endl; | ||
std::cout << "Time Limit:" << maxTime << " s" | ||
<< std::endl; | ||
std::cout << "Memory Limit:" << maxMem << " MB" | ||
<< std::endl; | ||
std::cout << "Compare Mode:Text"; | ||
std::cout << "\033[0m" << std::endl; | ||
opt.insert("TimeMode", TimeMode::perTask); | ||
opt.insert("TimeLimit", static_cast<int64_t>( | ||
maxTime * 1000000)); | ||
opt.insert("MemoryLimit", maxMem << 10); | ||
opt.insert("CompareMode", CompareMode::Text); | ||
opt.insert("TimeSamples", | ||
fs::path("CheckerDir/UOJ-Samples")); | ||
return true; | ||
} | ||
static bool runUOJ(const fs::path& exec) { | ||
line("Loading Problem Info"); | ||
std::string execName = | ||
exec.stem().string().substr(3); | ||
int id = scan<int>(execName); | ||
Option opt; | ||
opt.insert("Exec", exec); | ||
std::string problem; | ||
if(!loadProblemInfo("UOJ", id, problem)) | ||
return false; | ||
if(!readOpt(opt, problem)) | ||
return false; | ||
auto data = scanData(); | ||
runAll(opt, data); | ||
return true; | ||
} | ||
static OJAdapterInfo | ||
reg("UOJ-Judger", std::regex("(UOJ|uoj)[0-9]+\\S*", | ||
regexFlag4Match), | ||
runUOJ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "Network.hpp" | ||
bool download(const std::string& url, | ||
const fs::path& dst) { | ||
std::cout << "Downloading file " << url | ||
<< std::endl; | ||
line("wget"); | ||
std::string cmd = "wget --dns-timeout=20 " | ||
"--connect-timeout=20 " | ||
"--read-timeout=600 " | ||
"--tries=5 -v " | ||
"--no-use-server-" | ||
"timestamps -O " + | ||
dst.string() + " " + url; | ||
std::cout << cmd << std::endl; | ||
int res = system(cmd.c_str()); | ||
line(""); | ||
return res == 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#pragma once | ||
#include "Common.hpp" | ||
bool access(const std::string& url, | ||
const std::string& name); | ||
bool download(const std::string& url, | ||
const fs::path& dst); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
\section{贝尔数} | ||
贝尔数$B_n$是大小为$n$的集合的划分方案数。 | ||
|
||
贝尔数的前几项为:$1, 1, 2, 5, 15, 52, 203, 877,\cdots$(参见OEIS-A000110\\ | ||
\url{https://oeis.org/A000110}) | ||
|
||
$B_n$满足等式: | ||
\begin{eqnarray*} | ||
B_0=B_1&=&1\\ | ||
B_{n+1}&=&\sum_{i=0}^n{\binomial{n}{i}B_i}\\ | ||
B_n&=&\sum_{i=1}^n{\stirlingB{n}{i}} | ||
\end{eqnarray*} | ||
|
||
\subsection{因子分解应用} | ||
若无平方因子的整数$\displaystyle n=\sum_{i=1}^k{p_i}$, | ||
则整数$n$可以分解为$B_k$种因子的乘积表达式。 | ||
\subsection{贝尔数计算} | ||
\subsubsection{DFS}若要得到不同方案的状态表示,限制下阶段DFS的集合大小以避免重复计算。 | ||
\subsubsection{贝尔三角形} | ||
与推杨辉三角形类似,递推方法如下: | ||
\begin{eqnarray*} | ||
A[0][1]&=&1\\ | ||
A[n][1]&=&A[n-1][n]\\ | ||
A[n][m]&=&A[n][m-1]+A[n-1][m-1]\\ | ||
B_n&=&A[n][1] | ||
\end{eqnarray*} | ||
使用滚动数组优化空间。 | ||
|
||
\index{*TODO!贝尔三角形的意义} | ||
\subsubsection{生成函数法} | ||
利用Bell数的生成函数$e^{e^x-1}$,计算多项式exp。 | ||
\subsubsection{贝尔数模质数} | ||
\index{T!Touchard's Congruence} | ||
\begin{theorem}{Touchard's Congruence} | ||
\begin{eqnarray*} | ||
B_{p+n}&\equiv& B_n+B_{n+1}\pmod{p}\\ | ||
B_{p^m+n}&\equiv& mB_n+B_{n+1}\pmod{p}\\ | ||
\end{eqnarray*} | ||
\end{theorem} | ||
|
||
首先$O(p^2)$使用贝尔三角形预处理出$p$以内的贝尔数模$p$的值。 | ||
|
||
若要求$B_n$,则对$n$进行$p$进制分解,记$n_i$为$n$在权为$p^i$时的位。 | ||
|
||
以最低位作为下标,从$B_{0\ldots p}$开始递推,逐步加$p^i$递推直至次数等于$n_i$。 | ||
最后取数组第$n_0$项。 | ||
|
||
参考代码(PA2008 Cliquers Strike Back): | ||
\lstinputlisting{Source/Source/Count/bzoj3501.cpp} | ||
|
||
时间复杂度$O(p^2lg_pn)$。 | ||
|
||
该内容参考了Claris的博客\footnote{ | ||
BZOJ3501 : PA2008 Cliquers Strike Back | ||
\url{https://www.cnblogs.com/clrs97/p/4714467.html} | ||
}和Wikipedia-EN\footnote{ | ||
Bell number - Wikipedia:Modular arithmetic\\ | ||
\url{https://en.wikipedia.org/wiki/Bell\_number\#Modular\_arithmetic} | ||
}。 | ||
{\bfseries 令人失望的是维基百科已全面被封。} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.