【HDOJ】1033 Edge

时间:2023-03-08 23:22:57
【HDOJ】1033 Edge

题目英文太多,简单翻译了一下:
1. For products that are wrapped in small packings it is necessary that the sheet of paper
   containing the directions for use is folded until its size becomes small enough.
    对于那些使用小包包裹的产品,包含所使用方向的包装纸应当折叠起来并且足够小。    
2. We assume that a sheet of paper is rectangular and only folded along lines parallel to its initially shorter edge.
    我们假定包装纸是长方形,并且仅可以沿着平行于初始较短边对折。
3. The act of folding along such a line, however, can be performed in two directions: either the surface on the top of the sheet is brought together, or the surface on its bottom.
    折叠的动作尽管只能沿着一条线,但是却可以沿着两个方向进行:或者将包装纸的顶部折叠在一起,或者将底部折叠在一起。
4. In both cases the two parts of the rectangle that are separated by the folding line are laid together neatly and we ignore any differences in thickness of the resulting folded sheet.
    两种情况下,长方形都被折叠线分成两部分并且整齐的叠放在一起,这里我们忽略折叠包装纸的厚度差异。
5. After several such folding steps have been performed we may unfold the sheet again and take a look at its longer edge holding the sheet so that it appears as a one-dimensional curve, actually a concatenation of line segments.
    在经过几次折叠后,我们重新打开包装纸并且观察包装纸的较长边的边缘,它看起来像一维曲线,事实上是级联的线段。
6. If we move along this curve in a fixed direction we can classify every place where the sheet was folded as either type A meaning a clockwise turn or type V meaning a counter-clockwise turn.
    如果我们沿着曲线的固定方向移动,我们可以将每个折叠区域分类,沿顺时针方向为A,逆时针方向为V。
7. Given such a sequence of classifications, produce a drawing of the longer edge of the sheet assuming 90 degree turns at equidistant places.
    给定这样一个分类序列,在包装纸等距的地方沿给定方向转90度然后画线。
其实非常简单,程序如下:

 #include <stdio.h>
#include <string.h> #define MAXNUM 205
char buf[MAXNUM]; int v_dir[][] = {{, }, {, }, {-, }, {, -}};
int a_dir[][] = {{, }, {, -}, {-, }, {, }}; int setnextdir(int dirs[][], int dir[]) {
int i, index = -; for (i=; i<; ++i)
if (dirs[i][]==dir[] &&dirs[i][]==dir[]) {
index = i;
break;
} if (index >= ) {
index = (index+) & ;
dir[] = dirs[index][];
dir[] = dirs[index][];
return ;
}
return ;
} int main() {
int pos[];
int dir[];
int i; while (scanf("%s", buf) != EOF) {
getchar();
// initial
pos[]=; pos[]=;
dir[]=; dir[]=;
printf("300 420 moveto\n");
pos[] += dir[];
pos[] += dir[];
printf("%d %d lineto\n", pos[], pos[]); for (i=; i<(int)(strlen(buf)); ++i) {
if (buf[i] == 'A')
setnextdir(a_dir, dir);
else
setnextdir(v_dir, dir);
pos[] += dir[];
pos[] += dir[];
printf("%d %d lineto\n", pos[], pos[]);
} printf("stroke\nshowpage\n");
} return ;
}