杭电 1033【转向】

Edge

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
 
/*
*转向,A表示向右转,V表示向左转,每次是走长度为10,开始转向之前要向右先走10个长度
*每次转向是相对于上次行走的方向
*/
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
	//按照题目要求a作为横坐标初始化为300,c作为纵坐标初始化为420,在之后的代码里表现
    int a=300,b,c,n,x,y,i;
	//按照题目要求输入的转向命令最长为200
    char d[200];
    while(cin>>d)
    {
		//使用strlen函数在n中获取到转向命令的长度
        n=strlen(d);
		//按照题目要求转向之前有要先向右走一次
        b=310;c=420;
		//按照输出要求输出起始地址然后输出moveto,输出第一次行走后的地址输出lineto开始转向
        cout<<a<<" "<<c<<" "<<"moveto"<<endl;
        cout<<b<<" "<<c<<" "<<"lineto"<<endl;
		//x表示横坐标,y表示纵坐标,起先需要向右行走一次所以x记录为1,y记录为0.
        x=1;y=0;
        for(i=0;i<n;i++)
        {
			//如果遇到右转指令需要通过之前的行走方向确定相对右转后的走向
            if(d[i]=='A')
            {
				//如果x等于1表示之前是向右走的,此时的相对右转需要向下走,而横轴不动所以y记为-1,x记为0;纵轴坐标减10,以下同理
                if(x==1)
                {y=-1;x=0;c-=10;}
                else if(x==-1)
                {y=1;x=0;c+=10;}
                else if(y==1)
                {x=1;y=0;b+=10;}
                else if(y==-1)
                {x=-1;y=0;b-=10;}
            }
			//如果遇到左转指令也需要通过之前的行走方向确定相对左转后的走向,与上方代码同理
            if(d[i]=='V')
            {
                if(x==1)
                {y=1;x=0;c+=10;}
                else if(x==-1)
                {y=-1;x=0;c-=10;}
                else if(y==1)
                {x=-1;y=0;b-=10;}
                else if(y==-1)
                {x=1;y=0;b+=10;}
            }
			//每进行一次转向后输出目前所在坐标,并输出lineto,接着通过n以内的for循环进行下一次的转向
            cout<<b<<" "<<c<<" "<<"lineto"<<endl;
        }
		//转向均进行完成后,按照代码要求输出stroke和showpage两行字符串
        cout<<"stroke"<<endl<<"showpage"<<endl;
    }
    return 0;
}

 

多源动态最优潮流的分布鲁棒优化方法(IEEE118节点)(Matlab代码实现)内容概要:本文介绍了基于Matlab代码实现的多源动态最优潮流的分布鲁棒优化方法,适用于IEEE118节点电力系统。该方法结合两阶段鲁棒模型与确定性模型,旨在应对电力系统中多源不确定性(如可再生能源出力波动、负荷变化等),提升系统运行的安全性与经济性。文档还列举了大量相关的电力系统优化研究案例,涵盖微电网调度、电动汽车集群并网、需求响应、配电网重构等多个方向,并提供了YALMIP等工具包的网盘下载链接,支持科研复现与进一步开发。整体内容聚焦于电力系统建模、优化算法应用及鲁棒性分析。; 适合人群:具备电力系统基础知识和Matlab编程能力的研究生、科研人员及从事能源系统优化的工程技术人员;熟悉优化建模(如鲁棒优化、分布鲁棒优化)者更佳。; 使用场景及目标:①开展电力系统动态最优潮流研究,特别是含高比例可再生能源的场景;②学习和复现分布鲁棒优化在IEEE118等标准测试系统上的应用;③进行科研项目开发、论文复现或算法比较实验;④获取相关Matlab代码资源与仿真工具支持。; 阅读建议:建议按文档结构逐步浏览,重点关注模型构建思路与代码实现逻辑,结合提供的网盘资源下载必要工具包(如YALMIP),并在Matlab环境中调试运行示例代码,以加深对分布鲁棒优化方法的理解与应用能力。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值