1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
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}
|