关于自动AC机

Posted gtba

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于自动AC机相关的知识,希望对你有一定的参考价值。

嗯,,,,自动AC机

在cena评测时:

Const
    SourcePath:string=incantation;
    InputFile:string=incantation.in;
    OutputFile:string=incantation.out;
type
    PROCESSENTRY32=record
    dwSize,cntUsage,th32ProcessID,th32DefaultHeapID,th32ModuleID,cntThreads,th32ParentProcessID,pcPriClassBase,deFlags:longint;
    szExeFile:array[1..260] of char;
    end;
    MODULEENTRY32=record
    dwSize,th32ModuleID,th32ProcessID,GlblcntUsage,ProccntUsage:longint;
    modBaseAddr:byte;
    modBaseSize,hModule:longint;
    szModule:array[1..256] of char;
    szExePath:array[1..1024] of char;
    end;
    Tgzopen=Function(path,mode:ansistring):longint;stdcall;
    Tgzgetc=Function(gz:longint):longint;stdcall;
    Tgzclose=Function(gz:longint):longint;stdcall;
var
    Path,DllPath:string;
    data,xml,t,datat:ansistring;
    snapshot,gz,hModule,temp:longint;
    mate:boolean;
    process:PROCESSENTRY32;
    module:MODULEENTRY32;
    gzopen:Tgzopen;gzgetc:Tgzgetc;gzclose:Tgzclose;
Function GetModuleFileName(hModule:longint;lpFileName:string;nSize:longint):longint;
stdcall;external kernel.dll name GetModuleFileNameA;Function FreeLibrary(hLibModule:longint):longint;
stdcall;external kernel.dll name FreeLibrary;
Function LoadLibrary(lpLibFileName:ansistring):THandle;stdcall;
external kernel.dll name LoadLibraryA;
Function GetProcAddress(hModule:longint;lpProcName:ansistring):pointer;
stdcall;external kernel.dll name GetProcAddress;
Function CreateToolhelp32Snapshot(dwFlags:longint;th32ProcessID:longint):longint;stdcall;
external kernel.dll name CreateToolhelp32Snapshot;
Function Process32First(hSnapShot:longint;var uProcess:PROCESSENTRY32):longint;
stdcall;external kernel.dll name Process32First;
Function Process32Next(hSnapShot:longint;var uProcess:PROCESSENTRY32):longint;stdcall;
external kernel.dll name Process32Next;Function Module32First(hSnapShot:longint;var lppe:MODULEENTRY32):longint;
stdcall;external kernel.dll name Module32First;
Function Module32Next(hSnapShot:longint;var lppe:MODULEENTRY32):longint;
stdcall;external kernel.dll name Module32Next;
BEGIN
GetModuleFileName(0,path,260);
path:=path[0]+Copy(path,1,pos(	mp‘,path));
snapshot:=CreateToolhelp32Snapshot(2,0);
process.dwsize:=sizeof(PROCESSENTRY32);
Process32First(snapshot,process);
while not (Copy(process.szExeFile,1,8)=cena.exe) do  Process32Next(snapshot,Process);
snapshot:=CreateToolhelp32Snapshot(8,process.th32ProcessID);
module.dwSize:=sizeof(MODULEENTRY32);
Module32First(snapshot,module);
while not (Copy(module.szmodule,1,9)=zlib1.dll) do Module32Next(snapshot,module);
Dllpath:=Copy(module.szExePath,1,pos(zlib1.dll,module.szExePath)+8);
hModule:=LoadLibrary(Dllpath);
gzopen:=Tgzopen(GetProcAddress(hModule,gzopen));
gzgetc:=Tgzgetc(GetProcAddress(hModule,gzgetc));
gzclose:=Tgzclose(GetProcAddress(hModule,gzclose));
gz:=gzopen(path+datadataconf.xml,rb);
for temp:=1 to 22 do gzgetc(gz);
temp:=gzgetc(gz);
while temp<>-1 do begin
xml:=xml+chr(temp);
temp:=gzgetc(gz);
end;
gzclose(gz);
FreeLibrary(hModule);
assign(input,InputFile);
reset(input);
while not eof do begin readln(t);
data:=data+t+#0;
end;
Delete(xml,1,pos("+SourcePath+" co,xml));
Delete(xml,1,pos(><i,xml));
repeat
Delete(xml,1,pos(><i,xml)+17);
assign(input,path+data‘+Copy(xml,1,pos(‘"‘,xml)-1));
reset(input);
mate:=true;
datat:=data;
while not eof do begin
if datat=‘‘ then begin mate:=false;break;end;
readln(t);
t:=t+#0;
if pos(t,datat)<>1 then begin mate:=false;break;end;
Delete(datat,1,Length(t));
end;
if datat<>‘‘ then mate:=false;
if mate then begin
Delete(xml,1,pos(=,xml)+1);
assign(input,path+data‘+Copy(xml,1,pos(‘"‘,xml)-1));
reset(input);
assign(output,OutputFile);
rewrite(output);
while not eof do begin readln(t);writeln(t);end;break;end;
until false;close(input);close(output);
END.

在lemon评测时:

#ifndef __linux__
#include<windows.h>
#endif
//#include<cstdlib>
//#include<sys/types.h>
//#include<unistd.h>
#include<dirent.h>
#include<string>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
string f=__FILE__;
int n,l;
typedef std::pair<int,string> p;
vector<p>v;
char s[1000];
inline char*rread(int&r,char*s) {
    r=0;
    while(*s<0||*s>9)s--;
    for(int b=1; *s>=0&&*s<=9; b*=10,s--)
        r+=b*(*s-0);
    return s;
}
#include<iostream>
int main() {
    f=f.substr(0,f.find_last_of(.,f.length()));
#ifdef __linux__
    DIR*dir=opendir(("../../data/"+f).c_str());
    dirent*ptr;
    while((ptr=readdir(dir))!=NULL)
        if((l=strlen(ptr->d_name))>3&&
                (string(ptr->d_name).rfind(".out",l)==l-4||
                 string(ptr->d_name).rfind(".ans",l)==l-4)) {
            rread(n,ptr->d_name+strlen(ptr->d_name));
            v.push_back(p(n,string(ptr->d_name)));
        }
    realpath(".",s);
#else
    f=f.substr(f.find_last_of(\,f.length())+1,f.length());
    WIN32_FIND_DATA d;
    HANDLE hFind=FindFirstFile(("..\..\data\"+f+"\*").c_str(), &d);
    do if((l=strlen(d.cFileName))>3&&
                (string(d.cFileName).rfind(".out",l)==l-4||
                 string(d.cFileName).rfind(".ans",l)==l-4)) {
            rread(n,d.cFileName+strlen(d.cFileName));
            v.push_back(p(n,string(d.cFileName)));
        }
    while (FindNextFile(hFind, &d) != 0);
    FindClose(hFind);
    GetModuleFileName(NULL,s,1000);
#endif
    rread(n,rread(l,s+strlen(s)));
    sort(v.begin(),v.end());
#ifdef __linux__
    system(("cp -f ../../data/"+f+/+v[n].second+" "+f+".out").c_str());
#else
    system(("copy ..\..\data\"+f+\+v[n].second+" "+f+".out").c_str());
#endif
    return 0;
}

这是利用评测系统的bug来实现的。

这个东西可以在平时的时候玩一玩,但考试的时候还是要凭借真材实料。

一世安宁

以上是关于关于自动AC机的主要内容,如果未能解决你的问题,请参考以下文章

HDU3247 Resource Archiver(AC自动机+BFS+DP)

POJ2778DNA Sequence(AC自动机)

POJ3691DNA repair(AC自动机,DP)

HDU4057 Rescue the Rabbit(AC自动机+状压DP)

POJ - 2778 ~ HDU - 2243 AC自动机+矩阵快速幂

Codeforces 86C Genetic engineering(AC自动机+DP)