zoukankan      html  css  js  c++  java
  • Gym

    http://codeforces.com/gym/102219/problem/A

    Mental rotation is a difficult thing to master. Mental rotation is the ability to imagine in your mind how an object would look like from a viewer's side if you were to rotate it in a particular direction. It is something very important for engineers to learn and master, especially if you are required to do engineering drawing. There are many stages to these mental rotation tasks. We will approach a simple rotation task in this problem.

    If you are given the following square -

    After rotating it to the right once, it will look like the following -

    After rotating it to the left once, it will look like the following -

    For this problem you will be given an initial square of size n and a list of rotations to perform.

    Your task is to output the final representation of the square after performing all the rotation.

    Input

    The first line of input contains an integer N(1 ≤ N ≤ 1000). and a string containing a combination of ′L′ and ′R′. Where ′L′ means left rotation and ′R′ means right rotation. Length of the string will not exceed 100. Starting from the second line, the following N line each will contain N of the following characters (>, <, ∨, ∧ or .). Empty space is indicated by a '.' (dot).

    Output

    The output should be N

    lines, each containing N characters representing the final representation of the square after all the rotation. For ∨ and ∧ use v

    (small v) and Shift+6 respectively.

    Examples

    Input

    3 R
    >v>
    ...
    <^<
    

    Output

    ^.v
    >.<
    ^.v
    

    Input

    3 L
    >v>
    ...
    <^<
    

    Output

    ^.v
    >.<
    ^.v
    

    Input

    3 LL
    >v>
    ...
    <^<
    

    Output

    >v>
    ...
    <^<
    

    题意分析:

    给出一个矩阵,在给出一个字符串,L 代表逆时针, R 代表顺时针,求旋转后的矩阵,旋转后相应的字符也会转变,如v顺时针旋转是<,逆时针旋转是>。

    解题思路:

    先把顺时针旋转次数和逆时针旋转次数记录,转4次之后会回到原位,所以都可以对4取余,逆时针1次=顺时针3次,所以又可以全部转化成顺时针旋转。

    旋转我先用一个数组存旋转后的矩阵,再把矩阵复制到原数组中,把第一排旋转到倒数第一列,把第二排旋转到倒数第二列,以此类推。

    #include <stdio.h>
    #include <string.h>
    #define N 1020
    char a[N][N], a1[N][N], str[N];
    int n;
    void Right()
    {
    	for(int i=1; i<=n; i++)
    		for(int j=1; j<=n; j++)
    		{
    			if(a[i][j]=='^')
    				a1[j][n-i+1]='>';
    			else if(a[i][j]=='v')
    				a1[j][n-i+1]='<';
    			else if(a[i][j]=='<')
    				a1[j][n-i+1]='^';
    			else if(a[i][j]=='>')
    				a1[j][n-i+1]='v';
    			else a1[j][n-i+1] ='.';
    		}
    	for(int i=1; i<=n; i++)
    		for(int j=1; j<=n; j++)
    			a[i][j]=a1[i][j];
    }
    int main()
    {
    	int l, r;
    	while(scanf("%d%s", &n, str)!=EOF)
    	{
    		for(int i=1; i<=n; i++)
    			scanf("%s", a[i]+1);
    		l=0;r=0;
    		for(int i=0; i<strlen(str); i++)
    		{
    			if(str[i]=='L')
    				l++;
    			else
    				r++;
    		}
    		l%=4;
    		r%=4;
    		r=(r-l+4)%4;
    		while(r--)
    			Right();
    		for(int i=1; i<=n; i++)
    			printf("%s
    ", a[i]+1);
    	}
    	return 0;
    }
  • 相关阅读:
    【应用】Linux内存调试工具:valgrind
    Python UnboundLocalError: local variable 'xxx' referenced before assignment 解决方法
    MYSQL连接时错误码2059解决办法
    Python encode()、decode()方法详解
    genymotion自动化使用
    论文数据集
    Native Apps、Web Apps和Hybrid Apps
    C# 中如何进行私有(private)函数测试
    Windows10 计划任务开始失败
    如果系统盘后面是恢复盘,如何扩充系统盘
  • 原文地址:https://www.cnblogs.com/zyq1758043090/p/11852515.html
Copyright © 2011-2022 走看看