Peng Lv

毋意,毋必,毋固,毋我。 言必行,行必果。

导航

POJ 2556 Edge

题意:好久没做题,毕业之前心血来潮做几个题,随便选了个水题,就是2556,结果恶心了,题目看了好几遍,愣是没懂,看了看例子的图像,才知道input,output是什么意思。大致是A是顺时针拐,V是逆时针拐,最后输出路径。第一次连题目都没看懂AC了。

#include <iostream>
#include
<cstdio>
#include
<algorithm>
#include
<memory.h>
#include
<cmath>
#include
<bitset>
#include
<queue>
#include
<vector>
using namespace std;

const int MAXN = 1010;
const int INF = 0x4ffffff;

#define CLR(x,y) memset(x,y,sizeof(x))
#define ABS(x) ((x)>0?(x):-(x))

char str[300];
int dir[4][2] = {{10,0},{0,-10},{-10,0},{0,10}};


int work()
{
int i,j,tmp,k;
int n = strlen(str);
int cur = 0;
int x = 300;
int y = 420;
printf(
"%d %d moveto\n",x,y);
x
+= 10;
printf(
"%d %d lineto\n",x,y);

for(i = 0; i < n; ++i)
{
if(str[i] == 'A')
cur
= ((++cur)&3);
else if(str[i] == 'V')
cur
= ((--cur+4)&3);
x
+= dir[cur][0];
y
+= dir[cur][1];
printf(
"%d %d lineto\n",x,y);
}
printf(
"stroke\nshowpage\n");
return 0;
}
int main()
{
while(scanf("%s",str) != EOF)
{
work();
}
return 0;
}

posted on 2011-05-31 13:52  Lvpengms  阅读(457)  评论(0编辑  收藏  举报