zoukankan      html  css  js  c++  java
  • Edge(简单)

    Edge 分享至QQ空间 去爱问答提问或回答

    时间限制(普通/Java):1000MS/10000MS     运行内存限制:65536KByte
    总提交: 1            测试通过: 0

    描述

    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. We assume that a sheet of paper is rectangular and only folded along lines parallel to its initially shorter edge. 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. 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.

    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. 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. Given such a sequence of classifications, produce a drawing of the longer edge of the sheet assuming 90 degree turns at equidistant places.

    输入

    The input contains several test cases, each on a separate line. Each line contains a nonempty string of characters A and V describing the longer edge of the sheet. You may assume that the length of the string is less than 200. The input file terminates immediately after the last test case.

    输出

    For each test case generate a PostScript drawing of the edge with commands placed on separate lines. Start every drawing at the coordinates (300,420) with the command "300 420 moveto". The first turn occurs at (310,420) using the command "310 420 lineto". Continue with clockwise or counter-clockwise turns according to the input string, using a sequence of "x y lineto" commands with the appropriate coordinates. The turning points are separated at a distance of 10 units. Do not forget the end point of the edge and finish each test case by the commands stroke and showpage.

    You may display such drawings with the gv PostScript interpreter, optionally after a conversion using the ps2ps utility.

    样例输入

    V
    AVV

    样例输出

    300 420 moveto
    310 420 lineto
    310 430 lineto
    stroke
    showpage
    300 420 moveto
    310 420 lineto
    310 410 lineto
    320 410 lineto
    320 420 lineto
    stroke
    showpage

    提示

    For the Sample Input:

    题目来源

    ULM 2003

    题目上传者

    crq

     

     1 #include <iostream>
     2 #include <string>
     3 #include <cstdio>
     4 #include <cmath>
     5 #include <cstring>
     6 #include <algorithm>
     7 #include <map>
     8 #include <vector>
     9 #include <set>
    10 #include <queue>
    11 #include <stack>
    12 #define LL long long
    13 #define MAXI 2147483647
    14 #define MAXL 9223372036854775807
    15 #define eps (1e-8)
    16 #define dg(i) cout << "*" << i << endl;
    17   
    18 using namespace std;
    19   
    20 int main()
    21 {
    22     char str[205];
    23     int x, y;
    24     int tag;
    25     //记录最近一次的改变:
    26     // x - 10 x + 10 y - 10 y + 10
    27     //   -1     1      -2     2
    28     while(scanf("%s", str) != EOF)
    29     {
    30         x = 300; y = 420;
    31         puts("300 420 moveto");
    32         for(int i = 0; str[i] != '\0'; ++i)
    33         {
    34             if(str[i] == 'V')
    35             {
    36                 if(i)
    37                 {
    38                     if(tag == -2) x += 10, tag = 1;
    39                     else if(tag == -1) y -= 10, tag = -2;
    40                     else if(tag == 1) y += 10, tag = 2;
    41                     else x -= 10, tag = -1;
    42                     printf("%d %d lineto\n", x, y);
    43                 }
    44                 else
    45                 {
    46                     x += 10;
    47                     printf("%d %d lineto\n", x, y);
    48                     y += 10;
    49                     tag = 2;
    50                     printf("%d %d lineto\n", x, y);
    51                 }
    52             }
    53             else
    54             {
    55                 if(i)
    56                 {
    57                     if(tag == -2) x -= 10, tag = -1;
    58                     else if(tag == -1) y += 10, tag = 2;
    59                     else if(tag == 1) y -= 10, tag = -2;
    60                     else x += 10, tag = 1;
    61                     printf("%d %d lineto\n", x, y);
    62                 }
    63                 else
    64                 {
    65                     x += 10;
    66                     printf("%d %d lineto\n", x, y);
    67                     y -= 10;
    68                     tag = -2;
    69                     printf("%d %d lineto\n", x, y);
    70                 }
    71             }
    72         }
    73         puts("stroke");
    74         puts("showpage");
    75     }
    76     return 0;
    77 }

     

     

  • 相关阅读:
    MytBatis错题分析
    Spring核心概念
    延迟与缓存
    MyBatis的关联查询
    Mabatis注解
    [leetcode]226. Invert Binary Tree翻转二叉树
    [leetcode]633. Sum of Square Numbers平方数之和
    [leetcode]296. Best Meeting Point最佳见面地点
    [leetcode]412. Fizz Buzz报数
    [leetcode]142. Linked List Cycle II找出循环链表的入口
  • 原文地址:https://www.cnblogs.com/cszlg/p/2932438.html
Copyright © 2011-2022 走看看