Python数据分析常用库

2021最新千月影视全新改版影视app系统源码(全开源)源码下载

  返回  

HDU 4452 模拟题

2021/8/21 19:02:58 浏览:

模拟就行 注意提前规划好,注意细节与细心

#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#define ENTER printf("\n");
using namespace std;
int n;
int dx[4] = { -1,1,0,0 };//0代表North,1代表South,2代表West,3代表East
int dy[4] = { 0,0,-1,1 };
char c1;
int s1, t1;
char c2;
int s2, t2;
int x1, yl, dir1;
int x2, y2, dir2;
int clock;
int Direction(char c)
{
	switch (c)
	{
	case 'N':return 0;
	case 'S':return 1;
	case 'W':return 2;
	case 'E':return 3;
	default:break;
	}
	return -1;
}
void turn_left(int *dir)
{
	switch (*dir)
	{
	case 0:*dir = 2; break;
	case 1:*dir = 3; break;
	case 2:*dir = 1; break;
	case 3:*dir = 0; break;
	default:break;
	}
}
void walk(int *x, int *y, int *dir, int distance)    //在一小时内从(x,y)顺着dir方向走distance步
{
	int newx = *x + distance * dx[*dir];
	int newy = *y + distance * dy[*dir];
	//printf("newx=%d\n", newx);
	//printf("newy=%d\n", newy);
	while (newx<1 || newx>n)
	{
		if (newx < 1)
		{
			newx = 2 - newx;
			*dir = 1;
		}
		if (newx > n)
		{
			newx = 2 * n - newx;
			*dir = 0;
		}
	}
	while (newy<1 || newy>n)
	{
		if (newy < 1)
		{
			newy = 2 - newy;
			*dir = 3;
		}
		if (newy > n)
		{
			newy = 2 * n - newy;
			*dir = 2;
		}
	}
	*x = newx;
	*y = newy;
}
void change_direction(int* x1, int* y1, int* dir1, int* x2, int* y2, int* dir2,int clock,int t1,int t2)
{
	if (*x1 == *x2 && *y1 == *y2)
	{
		int t = *dir1;
		*dir1 = *dir2;
		*dir2 = t;
	}
	else
	{   
		if (clock % t1 == 0)
			turn_left(dir1);
		if (clock % t2 == 0)
			turn_left(dir2);
	}
}
int main()
{
	while (scanf("%d", &n) != EOF)
	{
		if (!n)
			break;
		getchar();
		scanf("%c%d%d", &c1, &s1, &t1);
		getchar();
		scanf("%c%d%d", &c2, &s2, &t2);
		scanf("%d", &clock);
		dir1 = Direction(c1);
		x1 = 1; yl = 1;
		dir2 = Direction(c2);
		x2 = n; y2 = n;
		for (int i = 1; i <= clock;i++)
		{
			walk(&x1, &yl, &dir1, s1);
			walk(&x2, &y2, &dir2, s2);
			change_direction(&x1, &yl, &dir1, &x2, &y2, &dir2, i, t1, t2);
		}
		printf("%d %d\n", x1, yl);
		printf("%d %d\n", x2, y2);
	}
	return 0;
}

联系我们

如果您对我们的服务有兴趣,请及时和我们联系!

服务热线:18288888888
座机:18288888888
传真:
邮箱:888888@qq.com
地址:郑州市文化路红专路93号