#P6949. [ICPC2018 WF] Triangles

[ICPC2018 WF] Triangles

题目描述

For your trip to Beijing, you have brought plenty of puzzle books, many of them containing challenges like the following: how many triangles can be found in Figure I.1 ?

Figure I.1 : Illustration of Sample Input 22 .

While these puzzles keep your interest for a while, you quickly get bored with them and instead start thinking about how you might solve them algorithmically. Who knows, maybe a problem like that will actually be used in this year's contest. Well, guess what? Today is your lucky day!

输入格式

The first line of input contains two integers rr and c(1r3000,1c6000)c (1 \le r \le 3 000 , 1 \le c \le 6 000) , specifying the picture size, where rr is the number of rows of vertices and cc is the number of columns. Following this are 2r 1− 1 lines, each of them having at most 2c 1− 1 characters. Odd lines contain grid vertices (represented as lowercase xx characters) and zero or more horizontal edges, while even lines contain zero or more diagonal edges. Specifically, picture lines with numbers 4k +1+ 1 have vertices in positions 1,5,9,131 , 5 , 9 , 13 , . . . while lines with numbers 4k +3+ 3 have vertices in positions 3,7,11,153 , 7 , 11 , 15 , . . . . All possible vertices are represented in the input (for example, see how Figure I.1 is represented in Sample Input 22) . Horizontal edges connecting neighboring vertices are represented by three dashes. Diagonal edges are represented by a single forward slash (/)(‘/') or backslash ()ˊ(‘\') character. The edge characters will be placed exactly between the corresponding vertices. All other characters will be space characters. Note that if any input line could contain trailing whitespace, that whitespace may be omitted.

输出格式

Display the number of triangles (of any size) formed by grid edges in the input picture.

题目大意

简要题意: 输入 rr 行顶点,每行有 cc 列,顶点用 xx 表示,每个顶点用水平边(-)和对角边(用 /\ 表示)精确连接。总共 2r12 r - 1 行,每行最多有 2c12 c - 1 个字符,除上述字符外均为空白字符;行末可能存在可忽略的空格。你需要输出所输入的图中由网格边构成了多少个三角形(无论大小)。配图为样例 22

对于所有数据,1r30001 \le r \le 30001c60001 \le c \le 6000

3 3
x---x
 \ /
  x
 / \
x   x

1

4 10
x   x---x---x   x
     \ /   / \
  x   x---x   x   x
     / \ / \   \
x   x---x---x---x
   /   / \   \ / \
  x---x---x---x---x

12

提示

Time limit: 6 s, Memory limit: 1024 MB.