Loading

LaTeX CCF系考题模板 + 幻灯片模板

考题

\documentclass[UTF8,a4paper]{ctexart}
\usepackage{geometry}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{tabu}
\usepackage{xeCJK}
\usepackage{CJK}     
\usepackage{xeCJKfntef}                     
\usepackage{fancyhdr}               
\usepackage{graphicx}                 
\usepackage{lastpage}    
\usepackage{listings}
\usepackage{xcolor}
\usepackage{fontspec}
\usepackage{layout}
\usepackage{titletoc}
\usepackage[colorlinks,linkcolor=blue]{hyperref} 
\newcommand\filename[1]{\emph{\textbf{#1}}}
\newcommand\udot[1]{\textbf{\color{black}\CJKunderdot{\color{black}#1}}} % 第一个 color 调整加粗字体下着重号的颜色
\newcommand\newprob[2]{
    \newpage
    \pagestyle{fancy}
    \lhead{ChineseContestName} \rhead{#1(#2)}
    \cfoot{第 \thepage 页 \qquad 共 \pageref{LastPage} 页}
    \phantomsection
    \addcontentsline{toc}{section}{#1(#2)}
    \begin{center}
        \LARGE
        \textbf{#1}(#2)
    \end{center}
    \large
    %
    \textbf{【题目描述】}
    \phantomsection
    \addcontentsline{toc}{subsection}{【题目描述】}
}
\newcommand\para[1]{
    $ $ \\ 
    \textbf{【#1】}
    \phantomsection
    \addcontentsline{toc}{subsection}{【#1】}
}
\newcommand\sample[2]{
    $ $ \\ 
    \textbf{【样例} #1\textbf{#2】}
    \phantomsection
    \addcontentsline{toc}{subsection}{【样例 #1 #2】}
}
\lstset{
    basicstyle={      
        \color{black}
        \fontspec{Consolas}
    },
    keywordstyle={
        \color{blue}
        \fontspec{Consolas}
    },
    numberstyle={
        \color{black}
        \textbf
    },
    rulecolor=\color{blue},
    numbers=left,                               
    frame=single,                            
    frameround=tttt,
    morekeywords={Sample, Input, Output},   % 可以手动添加关键字
}
\setmonofont{Consolas}
\geometry{left=2.52cm,right=2.52cm,top=2.5cm,bottom=2.5cm}
\begin{document}
    \pagestyle{fancy}
    \lhead{ChineseContestName} \rhead{}
    \cfoot{第 \thepage 页 \qquad 共 \pageref{LastPage} \color{black} 页}
    \thispagestyle{empty}
    \addcontentsline{toc}{section}{注意事项}
    \begin{center}
        \Huge
        \textbf{ChineseContestName}
        \\
        \Huge 
        EnglishContestName
        \\
        \huge
        \textit{SecondTitle}
        \\
        \Large
        \textbf{时间:}2021\textbf{年}1\textbf{月}1\textbf{日} 08:30 $\sim$ 1:00
        \\
    \end{center}
    \large
    \begin{center}
        \begin{tabular}{|p{3.1cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|}
        \hline
        题目名称 & First & Second & Third & Forth \\
        \hline
        题目类型 & 传统型 & 传统型 & 传统型 & 传统型 \\
        \hline
        目录 & \texttt{first} & \texttt{second} & \texttt{third} & \texttt{fourth} \\
        \hline
        可执行文件名 & \texttt{first} & \texttt{second} & \texttt{third} & \texttt{fourth} \\
        \hline
        输入文件名 & \texttt{first.in} & \texttt{second.in} & \texttt{third.in} & \texttt{fourth.in} \\
        \hline
        输出文件名 & \texttt{first.out} & \texttt{second.out} & \texttt{third.out} & \texttt{fourth.out} \\
        \hline
        每个测试点时限 & 1.0 秒 & 1.0 秒 & 1.0 秒 & 1.0 秒 \\
        \hline
        内存限制 & 256 MB & 256 MB & 256 MB & 256 MB \\
        \hline
        测试点数目 & 5 & 5 & 5 & 5 \\
        \hline
        测试点是否等分 & 是 & 是 & 是 & 是 \\
        \hline
        \end{tabular}
    \end{center}
提交源程序文件名
    \begin{center}
        \begin{tabular}{|p{3.1cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|}
        \hline
        对于 C++ \  语言 & \texttt{first.cpp} & \texttt{second.cpp} & \texttt{third.cpp} & \texttt{fourth.cpp} \\
        \hline
        对于 C \qquad 语言 & \texttt{first.c} & \texttt{second.c} & \texttt{third.c} & \texttt{fourth.c} \\
        \hline
        对于 Pascal 语言 & \texttt{first.pas} & \texttt{second.pas} & \texttt{third.pas} & \texttt{fourth.pas} \\
        \hline
        \end{tabular}
    \end{center}
编译选项
    \begin{center}
        \begin{tabular}{|p{3.1cm}|p{11.2cm}<\centering|}
        \hline
        对于 C++ \ 语言 & \texttt{-lm} \\
        \hline
        对于 C \qquad 语言 & \texttt{-lm} \\
        \hline
        对于 Pascal 语言 &  \\
        \hline
        \end{tabular}
    \end{center}
    \textbf{注意事项与提醒(请选手务必仔细阅读)} 
    \\
    \indent
    1. 文件名(程序名和输入输出文件名)必须使用英文小写。\par
    2. C/C++ 中函数 main() 的返回值类型必须是 int,程序正常结束时的返回值必须是 0。\par
    3. 提交的程序代码文件的放置位置请参照具体要求。\par
    4. 因违反以上三点而出现的错误或问题,申诉时一律不予受理。\par
    5. 若无特殊说明,结果的比较方式为全文比较(过滤行末空格及文末回车)。\par
    6. 程序可使用的栈内存空间限制与题目的内存限制一致。\par
    7. 只提供 Windows 格式附加样例文件。\par
    8. 评测在 Windows 下进行,各语言的编译器版本以其为准。
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newprob{First}{first} \\ \indent
Description. \par
求出\udot{至少}有多少个数满足条件。

\para{输入格式} \\ \indent
从文件 \filename{first.in} 中读入数据。 \par
包含一个正整数 $n$。

\para{输出格式} \\ \indent
输出到文件 \filename{first.out} 中。 \par
Output. 

\sample{1}{输入}
\begin{lstlisting}
 Sample Input.
\end{lstlisting}

\sample{1}{输出}
\begin{lstlisting}
 Sample Output.
\end{lstlisting}

\sample{1}{解释} \\ \indent
Note.

\sample{2}{} \\ \indent
见选手目录下的 \filename{first/first2.in} 与 \filename{first/first2.ans}。

\para{数据范围} \\ \indent
\begin{center}
    \begin{tabu}{c|c|c|c}
        \tabucline[2pt]{-}
        测试点编号 & $n \le$ & $m \le$ & 特殊限制 \\ \tabucline[1.2pt]{-}
        $1 \sim 4$ & $15$ & $2000$ & \multirow{2}{*}{无} \\ \cline{1-3}
        $5 \sim 8$ & $2000$ & $15$ &  \\ \hline
        $9 \sim 12$ & \multicolumn{2}{c|}{$100$} & $c_i = C_j = 1$ \\ \hline
        $13 \sim 16$ & \multicolumn{2}{c|}{\multirow{3}{*}{$2000$}} & $w_i = W_j = 1$ \\ \cline{1-1} \cline{4-4}
        $17 \sim 20$ & \multicolumn{2}{c|}{} & $v_i = V_j = 1$ \\ \cline{1-1} \cline{4-4}
        $21 \sim 25$ & \multicolumn{2}{c|}{} & 无 \\ \tabucline[2pt]{-}
    \end{tabu}
\end{center}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newprob{Second}{second} \\ \indent
Description. 

\para{输入格式} \\ \indent
从文件 \filename{second.in} 中读入数据。 \par

\para{输出格式} \\ \indent
输出到文件 \filename{second.out} 中。 \par
Output. 

\sample{1}{输入}
\begin{lstlisting}
 Sample Input.
\end{lstlisting}

\sample{1}{输出}
\begin{lstlisting}
 Sample Output.
\end{lstlisting}

\sample{1}{解释} \\ \indent
Note.

\sample{2}{} \\ \indent
见选手目录下的 \filename{second/second2.in} 与 \filename{second/second2.ans}。

\para{数据范围} \\ \indent
Constraint.
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newprob{Third}{third} \\ \indent
Description. 

\para{输入格式} \\ \indent
从文件 \filename{third.in} 中读入数据。 \par

\para{输出格式} \\ \indent
输出到文件 \filename{third.out} 中。 \par
Output. 

\sample{1}{输入}
\begin{lstlisting}
 Sample Input.
\end{lstlisting}

\sample{1}{输出}
\begin{lstlisting}
 Sample Output.
\end{lstlisting}

\sample{1}{解释} \\ \indent
Note.

\sample{2}{} \\ \indent
见选手目录下的 \filename{third/third2.in} 与 \filename{third/third2.ans}。

\para{数据范围} \\ \indent
Constraint.
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newprob{Fourth}{fourth} \\ \indent
Description. 

\para{输入格式} \\ \indent
从文件 \filename{fourth.in} 中读入数据。 \par

\para{输出格式} \\ \indent
输出到文件 \filename{fourth.out} 中。 \par
Output. 

\sample{1}{输入}
\begin{lstlisting}
 Sample Input.
\end{lstlisting}

\sample{1}{输出}
\begin{lstlisting}
 Sample Output.
\end{lstlisting}

\sample{1}{解释} \\ \indent
Note.

\sample{2}{} \\ \indent
见选手目录下的 \filename{fourth/fourth2.in} 与 \filename{fourth/fourth2.ans}。

\para{数据范围} \\ \indent
Constraint.
\end{document}

一道题的格式为:

\newprob{中文名}{英文名} \\ \indent     % 除了大标题,还会自带一个【题目描述】标题
Description. \par
\udot{至少}有 $n$ 个数。                % \udot 包括了加粗和下着重点

\para{输入格式} \\ \indent
从文件 \filename{英文名.in} 中读入数据。 % \filename 支持斜体加粗

\para{输出格式} \\ \indent
输出到文件 \filename{英文名.out} 中。\par
Output. 

\sample{1}{输入}                       % 第一个数字是样例编号
\begin{lstlisting}                     % 推荐样例的每一行前面加一个空格,要不然太拥挤
 Sample Input.
\end{lstlisting}

\sample{1}{输出}
\begin{lstlisting}
 Sample Output.
\end{lstlisting}

\sample{1}{解释} \\ \indent            % 如果接下来写的是文字,要加上 "\\ \indent",否则不用
Note.

\sample{2}{} \\ \indent
见选手目录下的 \filename{second/second2.in} 与 > \filename{second/second2.ans}。

\para{数据范围} \\ \indent
Constraint.

by https://www.luogu.com.cn/blog/syksykCCC/latex-noip-template

幻灯片

\documentclass{beamer}
\usepackage[UTF8,noindent]{ctexcap}
\usepackage{listings}
\usepackage{ctex}
\usepackage{graphicx}
\lstset{
    columns          = flexible,    
    xleftmargin      = 20pt,
    xrightmargin     = 0pt,
 breaklines=true,
 basicstyle=\footnotesize, 
 numbers=left,                                        % 在左侧显示行号
 numberstyle=\tiny\color{gray},                       % 设定行号格式
 frame=none,                                          % 不显示背景边框
 backgroundcolor=\color[RGB]{245,245,244},            % 设定背景颜色
 keywordstyle=\color[RGB]{40,40,255},                 % 设定关键字颜色
 numberstyle=\footnotesize\color{darkgray},           
 commentstyle=\it\color[RGB]{0,96,96},                % 设置代码注释的格式
 stringstyle=\rmfamily\slshape\color[RGB]{128,0,0},   % 设置字符串格式
 showstringspaces=false,                              % 不显示字符串中的空格
 language=c++,                                        % 设置语言
}
% Warsaw
% PaloAlto
% AnnArbor
% Malmoe
\usetheme{Boadilla}
\useinnertheme{circles}
%\useoutertheme[height=0\textwidth,width=0.18\textwidth,hideothersubsections]{sidebar}
\useoutertheme{miniframes}
\usecolortheme{whale}

\newfontfamily\kaisu{STKaiti}       %定义华文楷体为\kaisu
\setsansfont{TeX Gyre Termes}       %设置西文字体为times new roman
\setCJKsansfont{SimSun}             %设置中文字体为宋体
\setCJKmonofont{STKaiti}
\setmonofont{TeX Gyre Termes}   
\setbeamerfont{frametitle}{family=\ttfamily}

\title{\texttt{浅谈基于反悔堆维护的贪心}}
\subtitle{\texttt{aka. 反悔贪心}}
\author{\texttt{gde11s}}
\institute{\texttt{赣州市厚德外国语学校}}
\date{ April 1. 2022 }
\begin{document}

\frame{\titlepage}

\begin{frame}
    $$\includegraphics[scale=0.31]{899.png}$$
\end{frame}

\begin{frame}{\textsc{Contents}}
    \tableofcontents
\end{frame}

\section{\texttt{反悔贪心前置知识}}

\begin{frame}{反悔贪心思想}

    \qquad 普通的贪心只是满足局部最优解,但有些题目并不满足局部最优解等于全局最优解的条件,于是我们引入反悔贪心,意在找出能让答案更优的替换,撤销之前的贪心步骤,更换当前更优的步骤,即“反悔操作”。

\end{frame}

\begin{frame}{反悔贪心思想}

    \qquad 普通的贪心只是满足局部最优解,但有些题目并不满足局部最优解等于全局最优解的条件,于是我们引入反悔贪心,意在找出能让答案更优的替换,撤销之前的贪心步骤,更换当前更优的步骤,即“反悔操作”。

    \qquad 不难发现反悔贪心的核心在于维护反悔操作所需的值,所以当有些题目可以很方便地维护出操作贡献时,就可以考虑一下反悔贪心

\end{frame}

\begin{frame}{反悔贪心思想}
    
    \qquad 普通的贪心只是满足局部最优解,但有些题目并不满足局部最优解等于全局最优解的条件,于是我们引入反悔贪心,意在找出能让答案更优的替换,撤销之前的贪心步骤,更换当前更优的步骤,即“反悔操作”。
    
    \qquad 不难发现反悔贪心的核心在于维护反悔操作所需的值,所以当有些题目可以很方便地维护出操作贡献时,就可以考虑一下反悔贪心。

    \quad

    \qquad 说白了,反悔贪心本质上就是跑一遍局部最优(假)贪心,再通过反悔操作逐步到达答案。

\end{frame}

\begin{frame}{反悔堆}
    \qquad 反悔堆思路是这样的,我们把操作的贡献分成几个单调的部分,并用堆维护,这样在反悔时就能较快地取出可能更优的情况。
\end{frame}

\begin{frame}[fragile]{反悔堆}
    \qquad 其实简单题可以直接上优先队列,先给个反悔堆代码:

    \begin{lstlisting}
    struct Node{
        int id,val;
        bool operator <(const Node &x)const{
            return x.val<val;
        }
    };
    struct deletable_heap{
        int op;
        priority_queue<Node> q;
        void upd() {while(!q.empty()&&opt[q.top().id]!=op) q.pop();}
        bool empty() {upd();return q.empty();}
        Node top() {upd();return q.top();}
        void push(Node x) {q.push(x);}
    };
    \end{lstlisting}

    \qquad \scriptsize 注:upd 指 将不是当前操作所需的元素弹出

\end{frame}

\section{\texttt{例题}}

\begin{frame}{例题1号}
    \qquad 来道例题讲一讲大概流程。

    \begin{block}{Description.}
        \qquad $n$ 天。第 $i$ 天上午会进货 $A_i$ 件商品,中午的时候会有顾客需要购买 $B_i$ 件商品,可以选择满足顾客的要求,或是无视掉他。如果要满足顾客的需求,就必须要有足够的库存。问最多能够满足多少个顾客的需求。

        \quad

        $1 \leq n \leq 250000,0 \leq a_i,b_i \leq 10^9$
    \end{block}
\end{frame}

\begin{frame}{例题1号}
    \begin{block}{Solution.}
        \qquad 每次能选就选,不能选时如果之前选的最大数大于当前数,那显然用当前数替换之前最大数要更优,这样贪心即可。
    \end{block}

    \qquad \scriptsize 题目来源:\href{https://www.luogu.com.cn/problem/P3545}{P3545 [POI2012]HUR-Warehouse Store}
\end{frame}

\end{document}
posted @ 2021-11-03 12:54  Quick_Kk  阅读(220)  评论(1编辑  收藏  举报