HDU-1033,Edge(简单的模拟题)

简介: HDU-1033,Edge(简单的模拟题)

Problem Description:


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.


Input:


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.


Output:


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.

网络异常,图片无法展示
|




Sample Input:


V


AVV


Sample Output:


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


解题思路:


题意就是说:有个人,它从点(300,420)出发,先向X轴正方向走一步(每一步是10),此时他面朝X轴正方向。然后开始按照输入的指令走,如果指令是V,这人就向他左手边走一步,如果指令是A,他就向右手边走一步;此人往哪个方向走了一步,他现在就面朝哪个方向;比如最初面朝X轴正方向,向左走了一步,那么显然,此人目前面朝Y轴正方向。(我在这里将1定义为x轴正方向,2定义为y轴正方向,3定义为x轴负方向,4定义为y轴负方向)


程序代码:


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define step 10
#define N 210
char  s[N];
int main()
{
  int sx=300,sy=420,x,y,dir;
  while(cin>>s)
  {
    x=sx;
    y=sy;
    printf("%d %d moveto\n",x,y);
    x+=step;
    dir=1;//第一步,向右走 
    printf("%d %d lineto\n",x,y);
    for(int i=0;i<strlen(s);i++)
    {
      switch(dir)
      {
        case 1://面朝x轴正方向 
        {
          if(s[i]=='V')//向左,转为y轴正方向 
          {
            y+=step;
            dir=2;
          }
          else//向右,转为y轴负方向 
          {
            y-=step;
            dir=4;
          }
          break;
        }
        case 2://面朝y轴正方向 
        {
          if(s[i]=='V')//向左,转为x轴负方向 
          {
            x-=step;
            dir=3; 
          }
          else//向右,转为x轴正方向 
          {
            x+=step;
            dir=1;
          }
          break;
        }
        case 3://面朝x轴负方向 
        {
          if(s[i]=='V')//向左,转为y轴负方向 
          {
            y-=step;
            dir=4;
          }
          else//向右,转为y轴正方向 
          {
            y+=step;
            dir=2;
          }
          break; 
        }
        case 4://面朝y轴负方向 
        {
          if(s[i]=='V')//向左,转为x轴正方向 
          {
            x+=step;
            dir=1;
          }
          else//向右,转为x轴负方向 
          {
            x-=step;
            dir=3;
          }
          break;
        }
      }
      printf("%d %d lineto\n",x,y);
    }
    printf("stroke\nshowpage\n");
  }
  return 0;
}


相关文章
|
存储 Kubernetes 应用服务中间件
k8s 1.24.3版本使用nfs-provisioner4.0.0动态创建PV
k8s 1.24.3版本使用nfs-provisioner4.0.0动态创建PV
2841 0
|
11月前
|
开发框架 小程序 IDE
鸿蒙原生开发手记:05-开发之外的那些事
鸿蒙原生开发手记:05-开发之外的那些事
369 10
|
10月前
|
数据采集 数据可视化 数据挖掘
金融波动率的多模型建模研究:GARCH族与HAR模型的Python实现与对比分析
本文探讨了金融资产波动率建模中的三种主流方法:GARCH、GJR-GARCH和HAR模型,基于SPY的实际交易数据进行实证分析。GARCH模型捕捉波动率聚类特征,GJR-GARCH引入杠杆效应,HAR整合多时间尺度波动率信息。通过Python实现模型估计与性能比较,展示了各模型在风险管理、衍生品定价等领域的应用优势。
899 66
金融波动率的多模型建模研究:GARCH族与HAR模型的Python实现与对比分析
|
数据采集
使用 Puppeteer 绕过 Captcha:实现商家数据自动化采集
本文介绍了如何使用Puppeteer结合代理IP和用户伪装技术,轻松绕过大众点评的Captcha验证,实现商家信息的高效采集。通过配置Puppeteer、设置代理和用户伪装参数、模拟人类操作等步骤,成功提取了目标页面的数据。该方法不仅提高了爬虫的稳定性和隐蔽性,还为市场研究和商业分析提供了有力支持。注意,数据采集需遵守法律法规及网站政策。
356 1
使用 Puppeteer 绕过 Captcha:实现商家数据自动化采集
|
11月前
|
存储 人工智能 开发工具
AI场景下的对象存储OSS数据管理实践
本文介绍了对象存储(OSS)在AI业务中的应用与实践。内容涵盖四个方面:1) 对象存储作为AI数据基石,因其低成本和高弹性成为云上数据存储首选;2) AI场景下的对象存储实践方案,包括数据获取、预处理、训练及推理阶段的具体使用方法;3) 国内主要区域的默认吞吐量提升至100Gbps,优化了大数据量下的带宽需求;4) 常用工具介绍,如OSSutil、ossfs、Python SDK等,帮助用户高效管理数据。重点讲解了OSS在AI训练和推理中的性能优化措施,以及不同工具的特点和应用场景。
988 10
Java中的多线程编程
【4月更文挑战第2天】在本文中,我们将深入探讨Java中的多线程编程。我们将首先介绍什么是线程,然后讨论如何在Java中创建和管理线程。接着,我们将探讨一些常见的多线程问题,如死锁和竞态条件,并讨论如何避免这些问题。最后,我们将通过一个实例来演示如何使用Java进行多线程编程。
uni-app 108群二维码生成(二)
uni-app 108群二维码生成(二)
123 0
|
消息中间件 缓存 NoSQL
redis的缓存击穿,缓存穿透,缓存雪崩
redis的缓存击穿,缓存穿透,缓存雪崩
207 0
leetcode-392:判断子序列
leetcode-392:判断子序列
100 0
|
开发工具 Android开发
Android获取SDK的版本信息
Android获取SDK的版本信息
175 0