summaryrefslogtreecommitdiff
path: root/sduacm2017/lec2
diff options
context:
space:
mode:
Diffstat (limited to 'sduacm2017/lec2')
-rw-r--r--sduacm2017/lec2/lec.pdfbin0 -> 781277 bytes
-rw-r--r--sduacm2017/lec2/lec.tex312
-rw-r--r--sduacm2017/lec2/zz1.pngbin0 -> 9919 bytes
-rw-r--r--sduacm2017/lec2/zz2.pngbin0 -> 353804 bytes
4 files changed, 312 insertions, 0 deletions
diff --git a/sduacm2017/lec2/lec.pdf b/sduacm2017/lec2/lec.pdf
new file mode 100644
index 0000000..7c69fbf
--- /dev/null
+++ b/sduacm2017/lec2/lec.pdf
Binary files differ
diff --git a/sduacm2017/lec2/lec.tex b/sduacm2017/lec2/lec.tex
new file mode 100644
index 0000000..ae972b0
--- /dev/null
+++ b/sduacm2017/lec2/lec.tex
@@ -0,0 +1,312 @@
+\documentclass[aspectratio=169,hyperref={pdfencoding=auto,psdextra}]{beamer}
+\usepackage[utf8]{inputenc}
+\usepackage{CJKutf8}
+\usepackage{ulem}
+\usepackage{graphicx}
+\usepackage{fancyvrb}
+\usepackage{amsmath}
+\usepackage{multicol}
+\usetheme{Malmoe}
+\usecolortheme{default}
+\begin{CJK*}{UTF8}{gbsn}
+\title{「有了他我们无法活」}
+\subtitle{——炮打司令部}
+\author{Chris Xiong}
+\date{2017-07-28}
+\begin{document}
+ \frame{\titlepage}
+ \begin{frame}
+ \frametitle{「有了他我们无法活」}
+ \framesubtitle{Outline}
+ \begin{itemize}
+ \item 采访
+ \item Faster I/O
+ \item C++11 / 14
+ \item Common pitfalls
+ \item Bitmask
+ \item Bitmask+dp
+ \item 如何让队友认错之如何表扬队友
+ \end{itemize}
+ \end{frame}
+ \begin{frame}
+ \frametitle{采访}
+ \framesubtitle{\sout{a.k.a. 教学质量检查}}
+ \begin{itemize}
+ \item 上次课讲的内容大家都听懂了吗?\pause
+ \item 什么?不懂?\pause
+ \item 那还记得上次讲的什么吗?\pause
+ \item 对不起,这次没有A Water Problem
+ \end{itemize}
+ \end{frame}
+ \begin{frame}[fragile]
+ \frametitle{Faster I/O}
+ Why?
+ \begin{itemize}
+ \item No need to parse the format string
+ \item Makes better use of the I/O buffer
+ \end{itemize}
+ \pause
+ How?
+ \begin{itemize}
+ \item \verb|.sync_with_stdio(false)|
+ \item \verb|getchar()|
+ \item \verb|fread()|
+ \end{itemize}
+\end{frame}
+ \begin{frame}[fragile]
+ \frametitle{Faster I/O}
+ \framesubtitle{Faster input - getchar()}
+ \begin{Verbatim}
+ int readint()
+ {
+ int ret=0;
+ char ch=getchar();
+ while(ch<'0'||ch>'9')
+ ch=getchar();
+ do
+ {
+ ret=ret*10+ch-'0';
+ ch=getchar();
+ }while(ch>='0'&&ch<='9');
+ return ret;
+ }
+ \end{Verbatim}
+\end{frame}
+ \begin{frame}[fragile]
+ \frametitle{Faster I/O}
+ \framesubtitle{Even faster input - fread()}
+ \begin{Verbatim}
+ char s[SOME_LARGE_VALUE];
+ size_t ptr,len;
+ len=fread(s,1,SOME_LARGE_VALUE,stdin);
+ int readint()
+ {
+ //replace getchar() with s[ptr++]
+ ...
+ }
+ \end{Verbatim}
+ \pause
+ Reading real numbers?
+\end{frame}
+ \begin{frame}[fragile]
+ \frametitle{Faster I/O}
+ \framesubtitle{Faster output}
+ \begin{itemize}
+ \item Print digit by digit
+ \item Save to buffer then \verb|fwrite()| to \verb|stdout|.
+ \end{itemize}
+\end{frame}
+ \begin{frame}[fragile]
+ \frametitle{C++11 / 14 - Useful features that reduces coding efforts}
+ \framesubtitle{C++11}
+ \begin{itemize}
+ \item Uniform initialization
+ \begin{Verbatim}
+ struct S{int a;double b;char c;};
+ S s{1,2.0,'3'};//s.a==1; s.b==2.0; s.c=='3';
+ \end{Verbatim}
+ \item Type inference
+ \begin{Verbatim}
+ std::set<int> s;
+ auto a=1;
+ auto it=s.begin();
+ \end{Verbatim}
+ \item Range-based for loop
+ \begin{Verbatim}
+ std::vector<int> v;
+ for(auto &i:v)...
+ \end{Verbatim}
+ \end{itemize}
+\end{frame}
+ \begin{frame}[fragile]
+ \frametitle{C++11 / 14 - Useful features that reduces coding efforts}
+ \framesubtitle{C++11 cont'd}
+ \begin{itemize}
+ \item Lambda functions
+ \begin{Verbatim}
+std::sort(p+1,p+nv,[o=p[0]](const v3d& a,const v3d& b)->bool
+ {
+ double cross=(a.x-o.x)*(b.y-o.y)-(b.x-o.x)*(a.y-o.y);
+ if(sgn(cross))return sgn(cross)>0;
+ double la=hypot(a.x-o.x,a.y-o.y);
+ double lb=hypot(b.x-o.x,b.y-o.y);
+ return la<lb;
+ }
+);
+ \end{Verbatim}
+ \item Right angle bracket
+ \begin{Verbatim}
+ std::vector<std::pair<int,int>> v;
+ \end{Verbatim}
+ \item \verb|long long int|\\
+ Yeah, it was not standard until C++11 (C99).
+ \end{itemize}
+\end{frame}
+ \begin{frame}[fragile]
+ \frametitle{C++11 / 14 - Useful features that reduces coding efforts}
+ \framesubtitle{C++11 STL}
+ \begin{itemize}
+ \item Hash tables\\
+ \verb|std::unordered_map, std::unordered_set|
+ \item \verb|std::tuple|
+ \item Regular expressions
+ \item Threading
+ \item Random number generators
+ \end{itemize}
+\end{frame}
+ \begin{frame}[fragile]
+ \frametitle{C++11 / 14 - Useful features that reduces coding efforts}
+ \framesubtitle{C++14}
+ C++14 is a small extension to C++11.
+ \begin{itemize}
+ \item Improved \verb|auto|
+ \begin{Verbatim}
+ auto factorial(int x){
+ if(x==1)return 1;
+ return x*factorial(x-1);
+ }
+ \end{Verbatim}
+ \item Improved lambda functions
+ \begin{Verbatim}
+ auto lambda=[](auto x,auto y){return x+y;};
+ \end{Verbatim}
+ \item Lambda capture expressions
+ \end{itemize}
+\end{frame}
+ \begin{frame}[fragile]
+ \frametitle{Common pitfalls}
+ \begin{itemize}
+ \item Huge global variable causes linkage error.
+ \begin{Verbatim}
+int a[1LL<<12][1LL<<48],b[1LL<<12][1LL<<48],c[1LL<<12][1LL<<48];
+int main(){c[0][0]=1;}
+ \end{Verbatim}
+ Compilation result:
+ \begin{Verbatim}
+g++ -Wall -std=c++14 -g -o "test" "test.cpp" -lm (in directory:
+/home/chrisoft/code)
+/tmp/ccOkFQ7A.o: In function `main':
+/home/chrisoft/code/test.cpp:2:(.text+0x6):
+relocation truncated to fit: R_X86_64_PC32 against symbol
+`c' defined in .bss section in /tmp/ccOkFQ7A.o
+collect2: error: ld returned 1 exit status
+Compilation failed.
+
+ \end{Verbatim}
+ \item relocation of \verb|.bss| section exceeding platform limitations.
+ \end{itemize}
+\end{frame}
+ \begin{frame}[fragile]
+ \frametitle{Common pitfalls}
+ \begin{itemize}
+ \item Stack size is very small compared to heap
+ \begin{Verbatim}
+int main(){int a[100000000];...}
+ \end{Verbatim}
+ \item Results in stack overflow.
+ \item Math library
+ \item \verb|memset()| TLE
+ \end{itemize}
+\end{frame}
+ \begin{frame}
+ \frametitle{Bitmask}
+ \begin{itemize}
+ \item A set in its binary form
+ \item Codeforces 550B\pause
+ \item Codeforces 579A
+ \end{itemize}
+ \end{frame}
+ \begin{frame}
+ \frametitle{Bitmask+dp}
+ \begin{itemize}
+ \item Concept of a \textbf{state}\pause
+ \item Value function\pause
+ \item Initial state
+ \end{itemize}
+ \end{frame}
+ \begin{frame}
+ \frametitle{Bitmask+dp}
+ \begin{itemize}
+ \item TSP(Travelling Salesman Problem)
+ \item Given a list of cities and the distances between each pair of cities,
+ what is the shortest possible route that visits each city exactly once and
+ returns to the origin city?\pause
+ \item f[s][i]: s: set of visited cites, i: current city
+ \item functional equation:
+ $
+ f[s][i]=
+ \displaystyle \min_{k:N}f[s-{i}][k]+dist[k][i] (k\notin s)
+ $
+ \item Initial state: f[U][0]=0;\pause
+ \item Variant\pause
+ \item Loop direction
+ \end{itemize}
+ \end{frame}
+ \begin{frame}
+ \frametitle{Bitmask+dp}
+ \begin{itemize}
+ \item TSP: POJ 3311
+ \item Counting: POJ 3254
+ \item f[i][s]: row i with set s occupied
+ \end{itemize}
+ \end{frame}
+ \begin{frame}
+ \frametitle{如何让队友认错之如何表扬队友}
+ \framesubtitle{队友需要表扬才能更有生产力}
+ \includegraphics[scale=0.75]{zz1.png}
+ \end{frame}
+ \begin{frame}
+ \frametitle{如何让队友认错之如何表扬队友}
+ \framesubtitle{光辉事迹}
+ \begin{itemize}
+ \item 比赛中要其他队伍帮忙写对拍
+ \item 比赛中睡3小时觉
+ \item 全权负责实验室事务
+ \item 发说说
+ \end{itemize}
+ \end{frame}
+ \begin{frame}
+ \frametitle{宇宙智障的说说}
+
+ \begin{multicols}{2}
+ 就终于考完试了\_(:зゝ∠)\_\\
+ 然而暑假这种?不存在的(滑稽\\
+ 还是献给辣鸡的(划掉)acm好了\\
+ 学期结束,事儿反而就又突然多了起来\\
+ 假装已有计划的专题训练\\
+ 各种姿势被虐的多校联合\\
+ 以及暑期集训的萌新教学\\
+ 与开始正式接手的实验室各种大小事务的锅\\
+ 相信,一定会是个忙碌的七八月份吧\\
+ 希望,也同会是个充满收获的七八月\\
+ 就也会更期待着\\
+ 在八月初的短假里\\
+ 与小姐姐愉快的玩耍呢\\
+ 总之,一定会是个不平凡的假期\\
+ 再以及,小姐姐寄的明信片也终于到了:)\\
+ \end{multicols}
+ \end{frame}
+
+ \begin{frame}
+ \frametitle{宇宙智障的说说}
+ \includegraphics[scale=0.5]{zz2.png}
+ \end{frame}
+ \begin{frame}
+ \frametitle{为何要表扬队友}
+ \begin{itemize}
+ \item 让恬不知耻的队友知道错(似乎对宇宙智障无效)
+ \item 叫醒队友
+ \item \sout{鼓励}队友\sout{WA更多题}
+ \end{itemize}
+ \end{frame}
+ \begin{frame}
+ \frametitle{放假事宜}
+ \begin{itemize}
+ \item 宇宙智障已经畏罪潜逃
+ \item 宇宙智障8月7日将被扭送
+ \item 大家一定不用比宇宙智障回来的早
+ \end{itemize}
+ \end{frame}
+\end{CJK*}
+\end{document}
+
diff --git a/sduacm2017/lec2/zz1.png b/sduacm2017/lec2/zz1.png
new file mode 100644
index 0000000..8e5bcf8
--- /dev/null
+++ b/sduacm2017/lec2/zz1.png
Binary files differ
diff --git a/sduacm2017/lec2/zz2.png b/sduacm2017/lec2/zz2.png
new file mode 100644
index 0000000..ce8d970
--- /dev/null
+++ b/sduacm2017/lec2/zz2.png
Binary files differ