├── config ├── tail ├── 图论 ├── 最短路 │ ├── config │ └── Dijkstra.cpp ├── 网络流 │ ├── config │ └── Dinic.cpp ├── config └── 强连通分量缩点.cpp ├── 字符串 ├── config └── Manacher.cpp ├── 结构.png ├── template.pdf ├── Makefile ├── README.md ├── head └── main.cpp /config: -------------------------------------------------------------------------------- 1 | 字符串 2 | 图论 -------------------------------------------------------------------------------- /tail: -------------------------------------------------------------------------------- 1 | \end{document} -------------------------------------------------------------------------------- /图论/最短路/config: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /字符串/config: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /图论/网络流/config: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /图论/config: -------------------------------------------------------------------------------- 1 | <最短路> <> <> <最短路> 2 | <网络流> <> <> <网络流> 3 | <强连通分量缩点> <强连通分量缩点.cpp> -------------------------------------------------------------------------------- /结构.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Chen-Jr/ICPC-Code-Template-in-Latex/HEAD/结构.png -------------------------------------------------------------------------------- /template.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Chen-Jr/ICPC-Code-Template-in-Latex/HEAD/template.pdf -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | template.pdf: template.tex main 2 | ./main 3 | pdflatex template.tex 4 | pdflatex template.tex 5 | 6 | template.tex: main 7 | 8 | main: main.cpp 9 | cc main.cpp -o main 10 | 11 | clean: 12 | rm template.* main 13 | -------------------------------------------------------------------------------- /图论/最短路/Dijkstra.cpp: -------------------------------------------------------------------------------- 1 | const int INF=0x3f3f3f3f; 2 | int head[maxn],cnt; 3 | struct edge{ 4 | int to,next; 5 | long long cost; 6 | }q[maxn]; 7 | void add_edge(int from,int to,int cost){ 8 | q[cnt].to=to; 9 | q[cnt].cost=cost; 10 | q[cnt].next=head[from]; 11 | head[from]=cnt++; 12 | } 13 | typedef pairP; 14 | long long d[maxn]; 15 | int a[maxn],b[maxn],c[maxn]; 16 | void dijikstra(int s){ 17 | memset(d,INF,sizeof(d)); 18 | priority_queue,greater

>que; 19 | d[s]=0; 20 | que.push(P(0,1)); 21 | while(!que.empty()){ 22 | P p=que.top(); 23 | que.pop(); 24 | int x=p.second; 25 | //if(d[x]d[x]+id.cost){ 29 | d[id.to]=d[x]+id.cost; 30 | que.push((P(d[id.to],id.to))); 31 | } 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /字符串/Manacher.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define maxn 2000005 3 | using namespace std; 4 | int mp[maxn]; 5 | string str; 6 | char c[maxn]; 7 | void Manacher(string s,int len){ 8 | int l=0,R=0,C=0;; 9 | c[l++]='$', c[l++]='#'; 10 | for(int i=0;ii?min(mp[2*C-i],R-i):1; 15 | while(i+mp[i]0){ 16 | if(c[i+mp[i]]==c[i-mp[i]]) mp[i]++; 17 | else break; 18 | } 19 | if(i+mp[i]>R){ 20 | R=i+mp[i], C=i; 21 | } 22 | } 23 | } 24 | int main() 25 | { 26 | int cnt=0; 27 | while(cin>>str){ 28 | if(str=="END") break; 29 | int len=str.length(); 30 | Manacher(str,len); 31 | int ans=0; 32 | for(int i=0;i<2*len+4;i++){ 33 | ans=max(ans,mp[i]-1); 34 | } 35 | printf("Case %d: %d\n",++cnt,ans); 36 | } 37 | return 0; 38 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ICPC-Code-Template-in-Latex 2 | 3 | 4 | 创建一个Latex版本的 ACM-ICPC 模板。 5 | 6 | 本项目主要以github的另一个项目:https://github.com/jasison27/ACM-ICPC-CodeTemplate-Late 为基础,进行了一定程度上的修改于完善: 7 | 8 | - 优化了排版 9 | - 优化了全文的代码显示 10 | - 支持中文 11 | - 可以在每一个Subciton/Subsection/Subsubsection后插入`.tex`文件,用来对当前的模板进行说明。 12 | - 支持subsubsection的建立。 13 | 14 | ## 文件结构: 15 | 16 | ![12](https://raw.githubusercontent.com/Chen-Jr/ICPC-Code-Template-in-Latex/master/%E7%BB%93%E6%9E%84.png) 17 | 18 | 其中: 19 | 20 | 1. 主文件中的 `config`文件为控制一级目录的配置文件,主要用来控制Section的输出。内部填写的名字代表着一个一级目录。该项需要使用者自行进行更改。 21 | 2. 主文件中的 `head`、`tail`、`main.cpp`文件**不建议**进行修改,直接使用即可。如果有意对生成的`tex`文件进行自定义修改,可以修改`head`以及`tail`文件。如果发现编译运行`main.cpp`文件时发生错误,可以根据`main.cpp`中的注释进行一定程度上的修改。 22 | 3. 一级目录中的`config`文件为当前目录的配置文件,主要用来控制Subsection的输出及判定是否存在Subsubsection。该文件存在四个参数: 23 | <二级目录名称> <代码文件> <三级目录名称> 24 | - <二级目录名称>:在<>内部填写当前你需要的二级目录(即Subsection)的名称 25 | - <代码文件>:在<>内部填写在当前二级目录中,你所需要插入的代码(支持`.java`/`.cpp`/`.py`文件)。**如果当前状态下无需代码,则在<>中间留空(如果没有后面两个参数,则可以直接省略<>)**, 26 | - :在<>内部填写在当前二级目录中,你所需要插入的说明文件`.tex`.**如果当前状态下无需代码,则在<>中间留空(如果没有最后一个参数,则可以直接省略<>)** 27 | - <三级目录名称>:如果你需要生成一个三级目录,则你只需要在在次项中填写于<二级目录名称>相同的名称。**注意:此时填写的名字代表的是一个二级目录,(是一个文件夹),此时第二个以及第三个参数需要留空** 28 | 4. 二级目录中的`config`文件配置跟上述相同,只需要照葫芦画瓢即可。 29 | 30 | ## 使用: 31 | 32 | ### 准备: 33 | 34 | ACM-ICPC模版库、g++环境、Latex发行版软件 35 | 36 | #### Linux: 37 | 38 | 直接make就可以了(如果没有安装Latex,需要自行安装一下texlive-full) 39 | 40 | #### Windows: 41 | 42 | **因为需要支持中文,故需要将Windows系统编码改为utf-8!!** 43 | 44 | 之后编译运行`main.cpp`,之后就会生成一份`template.tex`文件,最后只需要用Latex使用`XeLatex`编译生成pdf文件即可。 45 | -------------------------------------------------------------------------------- /图论/强连通分量缩点.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define maxn 200005 3 | using namespace std; 4 | struct edge{ 5 | int next,to; 6 | }q[maxn]; 7 | int head[maxn],dfn[maxn],low[maxn],cnt,tot; 8 | int vis[maxn],belong[maxn],index,belong_num[maxn],num_index; 9 | int indegree[maxn],outdegree[maxn]; 10 | void add_edge(int from,int to){ 11 | q[cnt].next=head[from]; 12 | q[cnt].to=to; 13 | head[from]=cnt++; 14 | } 15 | void init(){//初始化 16 | memset(vis,0,sizeof(vis)); 17 | memset(dfn,0,sizeof(dfn)); 18 | memset(head,-1,sizeof(head)); 19 | memset(low,0,sizeof(low)); 20 | memset(belong_num,0,sizeof(belong_num));//在某个连通块中有多少个结点 21 | memset(indegree,0,sizeof(indegree));//新图的入度 22 | memset(outdegree,0,sizeof(outdegree)); 23 | index=num_index=cnt=tot=0; 24 | } 25 | stackst; 26 | void tarjin(int x){//Tarjin的主体 27 | dfn[x]=low[x]=++tot; 28 | vis[x]=1; 29 | st.push(x); 30 | for(int i=head[x];i!=-1;i=q[i].next){ 31 | edge e=q[i]; 32 | if(!dfn[e.to]){ 33 | tarjin(e.to); 34 | low[x]=min(low[e.to],low[x]); 35 | } 36 | else if(vis[e.to]==1){ 37 | low[x]=min(low[x],dfn[e.to]); 38 | } 39 | } 40 | if(dfn[x]==low[x]){ 41 | int v; 42 | index=index+1; 43 | do{ 44 | v=st.top(); 45 | st.pop(); 46 | belong[v]=index; 47 | belong_num[index]++; 48 | vis[v]=0; 49 | }while(v!=x); 50 | } 51 | } 52 | void solve(int n,int m,int root){ 53 | for(int i=1;i<=n;i++){//对图进行Tarjin 54 | if(!dfn[i]){ 55 | tarjin(i); 56 | } 57 | } 58 | //如果连通分量只有一个,则直接输出0 59 | if(index==1){ 60 | puts("0"); 61 | return ; 62 | } 63 | indegree[belong[root]]=1;//确保初始点root所在的连通分量入度不为0 64 | 65 | for(int i=1;i<=n;i++){//重构图的过程 66 | for(int j=head[i];j!=-1;j=q[j].next){ 67 | edge e=q[j]; 68 | if(belong[i]==belong[e.to]) continue; 69 | indegree[belong[e.to]]++; 70 | outdegree[belong[i]]++; 71 | } 72 | } 73 | int cnt=0;//统计入度为0的点 74 | for(int i=1;i<=index;i++){ 75 | if(indegree[i]==0){ 76 | cnt++; 77 | } 78 | } 79 | cout< 2 | using namespace std; 3 | const int maxn=50005; 4 | const int maxm=500005; 5 | const int inf=0x3f3f3f3f; 6 | struct Node{ 7 | int to,val,next; 8 | }q[maxm<<1]; 9 | int head[maxn],cnt=0,dep[maxn],cur[maxn],vis[maxn]; 10 | int sp,ep,maxflow; 11 | void init(){ 12 | memset(head,-1,sizeof(head)); 13 | cnt=2,maxflow=0; 14 | } 15 | void addedge(int from,int to,int val){ 16 | q[cnt].to=to; 17 | q[cnt].val=val; 18 | q[cnt].next=head[from]; 19 | head[from]=cnt++; 20 | } 21 | void add_edge(int from,int to,int val){ 22 | addedge(from,to,val); 23 | addedge(to,from,0); 24 | } 25 | bool bfs(int n){ 26 | for(int i=0;i<=n;i++){ 27 | cur[i]=head[i],dep[i]=0x3f3f3f3f; 28 | vis[i]=0; 29 | } 30 | dep[sp]=0; 31 | queueque; 32 | que.push(sp); 33 | while(!que.empty()){ 34 | int x=que.front(); 35 | que.pop(); 36 | vis[x]=0; 37 | for(int i=head[x];i!=-1;i=q[i].next){ 38 | int to=q[i].to; 39 | if(dep[to]>dep[x]+1&&q[i].val){ 40 | dep[to]=dep[x]+1; 41 | if(!vis[to]){ 42 | que.push(to); 43 | vis[to]=1; 44 | } 45 | } 46 | } 47 | } 48 | if(dep[ep]!=inf) return true; 49 | else return false; 50 | } 51 | int dfs(int x,int flow){ 52 | int rlow=0; 53 | if(x==ep){ 54 | maxflow+=flow; 55 | return flow; 56 | } 57 | int used=0; 58 | for(int i=cur[x];i!=-1;i=q[i].next){ 59 | cur[x]=i; 60 | int to=q[i].to; 61 | if(q[i].val&&dep[to]==dep[x]+1){ 62 | if(rlow=dfs(to,min(flow-used,q[i].val))){ 63 | used+=rlow; 64 | q[i].val-=rlow; 65 | q[i^1].val+=rlow; 66 | if(used==flow) break; 67 | } 68 | } 69 | } 70 | return used; 71 | } 72 | int dinic(int n){ 73 | while(bfs(n)){ 74 | dfs(sp,inf); 75 | } 76 | return maxflow; 77 | } 78 | int main() 79 | { 80 | int n,m; 81 | scanf("%d%d%d%d",&n,&m,&sp,&ep); 82 | register int i; 83 | int u,v,val; 84 | init(); 85 | for(i=1;i<=m;i++){ 86 | scanf("%d%d%d",&u,&v,&val); 87 | add_edge(u,v,val); 88 | } 89 | printf("%d",dinic(n)); 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /head: -------------------------------------------------------------------------------- 1 | \documentclass[10pt,a4paper]{article} 2 | %\usepackage{zh_CN-Adobefonts_external} 3 | \usepackage{xeCJK} 4 | \usepackage{amsmath, amsthm} 5 | \usepackage{listings,xcolor} 6 | \usepackage{geometry} % 设置页边距 7 | \usepackage{fontspec} 8 | \usepackage{graphicx} 9 | \usepackage[colorlinks]{hyperref} 10 | \usepackage{setspace} 11 | \usepackage{fancyhdr} % 自定义页眉页脚 12 | 13 | 14 | \setsansfont{Consolas} % 设置英文字体 15 | \setmonofont[Mapping={}]{Consolas} % 英文引号之类的正常显示,相当于设置英文字体 16 | 17 | \linespread{1.2} 18 | 19 | \title{Template For ICPC} 20 | \author{ChenJr @ GDUT} 21 | \definecolor{dkgreen}{rgb}{0,0.6,0} 22 | \definecolor{gray}{rgb}{0.5,0.5,0.5} 23 | \definecolor{mauve}{rgb}{0.58,0,0.82} 24 | 25 | \pagestyle{fancy} 26 | 27 | \lhead{\CJKfamily{kai} GuangDong University of Technology} %以下分别为左中右的页眉和页脚 28 | \chead{} 29 | 30 | \rhead{\CJKfamily{kai} 第 \thepage 页} 31 | \lfoot{} 32 | \cfoot{\thepage} 33 | \rfoot{} 34 | \renewcommand{\headrulewidth}{0.4pt} 35 | \renewcommand{\footrulewidth}{0.4pt} 36 | %\geometry{left=2.5cm,right=3cm,top=2.5cm,bottom=2.5cm} % 页边距 37 | \geometry{left=3.18cm,right=3.18cm,top=2.54cm,bottom=2.54cm} 38 | \setlength{\columnsep}{30pt} 39 | 40 | \makeatletter 41 | 42 | \makeatother 43 | 44 | 45 | 46 | \lstset{ 47 | language = c++, 48 | numbers = left, 49 | numberstyle={ % 设置行号格式 50 | \small 51 | \color{black} 52 | \fontspec{Consolas} 53 | }, 54 | commentstyle = \color[RGB]{0,128,0}\bfseries, %代码注释的颜色 55 | keywordstyle={ % 设置关键字格式 56 | \color[RGB]{40,40,255} 57 | \fontspec{Consolas Bold} 58 | \bfseries 59 | }, 60 | stringstyle={ % 设置字符串格式 61 | \color[RGB]{128,0,0} 62 | \fontspec{Consolas} 63 | \bfseries 64 | }, 65 | basicstyle={ % 设置代码格式 66 | \fontspec{Consolas} 67 | \small\ttfamily 68 | }, 69 | emphstyle=\color[RGB]{112,64,160}, % 设置强调字格式 70 | breaklines=true, % 设置自动换行 71 | tabsize = 4, 72 | frame = single,%主题 73 | columns = fullflexible, 74 | rulesepcolor = \color{red!20!green!20!blue!20}, %设置边框的颜色 75 | showstringspaces = false, %不显示代码字符串中间的空格标记 76 | escapeinside={\%*}{*)}, 77 | } 78 | 79 | \begin{document} 80 | \title{ICPC Templates For Grooming} 81 | \author {ChenJr} 82 | \maketitle 83 | \tableofcontents 84 | \newpage 85 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | const int MAXL = 100000; 4 | const char* cf = "/config"; 5 | const char* tf = "template.tex"; 6 | const char* head = "head"; 7 | const char* tail = "tail"; 8 | int secn; 9 | char sec[2000][MAXL]; 10 | FILE* tex = NULL; 11 | char temp[MAXL],temp2[MAXL]; 12 | struct LineBreaker { 13 | char name[MAXL], file[MAXL], Texfile[MAXL], Subsubsec[MAXL]; 14 | // the four array mean that: 15 | // 1: the name of the current Section. 16 | // 2: the cpp/java/etc file int the current Section. 17 | // 3: the tex file in the current Section. 18 | // 4: weather there exists a subsubsection. 19 | int nl, fl, tex1, subsub; 20 | void solve(const char s[]) { 21 | nl = fl = tex1 = subsub=0; 22 | int i = 0; 23 | while (s[i] && s[i] != '<') i ++; 24 | if (s[i]) i ++; 25 | while (s[i] && s[i] != '>') name[nl++] = s[i++]; 26 | 27 | while (s[i] && s[i] != '<') i ++; 28 | if (s[i]) i ++; 29 | while (s[i] && s[i] != '>') file[fl++] = s[i++]; 30 | 31 | while (s[i] && s[i] != '<') i ++; 32 | if (s[i]) i ++; 33 | while (s[i] && s[i] != '>') Texfile[tex1++] = s[i++]; 34 | 35 | while (s[i] && s[i] != '<') i ++; 36 | if (s[i]) i++; 37 | while (s[i] && s[i] != '>') Subsubsec[subsub++] = s[i++]; 38 | 39 | name[nl] = file[fl] = Texfile[tex1] = Subsubsec[subsub] = 0; 40 | } 41 | }; 42 | 43 | // Find how many Sections the main tex have. 44 | void read_dir() { 45 | FILE* dir = fopen(cf+1, "r"); 46 | secn = 0; 47 | while (fgets(sec[secn++], MAXL, dir) != NULL) {} 48 | fclose(dir); 49 | while (sec[secn-1][0] == 0 && secn > 0) secn --; 50 | //update bug : original : (i0){ 89 | printf("\\begin{spacing}{1.5}\n\\input{%s/%s}\n\\end{spacing}\n",temp2,lb2.Texfile); 90 | fprintf(tex,"\\begin{spacing}{1.5}\n\\input{%s/%s}\n\\end{spacing}\n",temp2,lb2.Texfile); 91 | } 92 | if(lb2.fl==0) continue; 93 | fprintf(tex, "\\lstinputlisting{%s/%s}\n", temp2,lb2.file); 94 | } 95 | fclose(fp2); 96 | } 97 | 98 | int main() { 99 | tex = fopen(tf, "w"); 100 | file(head); 101 | read_dir(); 102 | for (int i = 0; i < secn; ++ i) { 103 | fprintf(tex, "\\section{%s}\n", sec[i]); 104 | memcpy(temp, sec[i], sizeof (temp) ); 105 | strcat(temp, cf); 106 | printf("section: %s\n", sec[i]); 107 | FILE* fp = fopen(temp, "r"); 108 | while(fgets(temp, MAXL, fp) != NULL) { 109 | 110 | // if the first letter in the line is not '<', then continue. 111 | if (temp[0] != '<') break; 112 | LineBreaker lb; 113 | lb.solve(temp); 114 | printf("subsection %s with %s\n", lb.name, lb.file); 115 | fprintf(tex, "\\subsection{%s}\n", lb.name); 116 | 117 | //check if there has a tex file 118 | if(lb.tex1>0){ 119 | printf("\\begin{spacing}{1.5}\n\\input{%s/%s}\n\\end{spacing}\n",sec[i],lb.Texfile); 120 | fprintf(tex,"\\begin{spacing}{1.5}\n\\input{%s/%s}\n\\end{spacing}\n",sec[i],lb.Texfile); 121 | } 122 | 123 | // if the second <> is empty, then continue. 124 | if(lb.subsub>0){ 125 | Subsubsection(lb,i); 126 | } 127 | 128 | //check if there has a cpp file 129 | if(lb.fl==0) continue; 130 | 131 | //gain the path for the cpp file 132 | memcpy(temp, sec[i], sizeof(temp) ); 133 | temp[strlen(temp)+1] = 0; 134 | temp[strlen(temp)] = '/'; 135 | 136 | strcat(temp, lb.file); 137 | fprintf(tex, "\\lstinputlisting{%s}\n", temp); 138 | } 139 | fclose(fp); 140 | } 141 | file(tail); 142 | fclose(tex); 143 | return 0; 144 | } 145 | --------------------------------------------------------------------------------