Hackonacci Matrix Rotations--模拟水题

Hackonacci Matrix Rotations

Your submission will run against only preliminary test cases. Full test cases will run at the end of the day.

We define a  series as follows:

We define a Hackonacci Matrix to be an  matrix where the rows and columns are indexed from  to , and the top-left cell is . Each cell  must contains either the character X or the character Y. If is even, it's X; otherwise, it's Y.

Next, we want to perform  queries where each query  consists of an integer, . Each  is a multiple of degrees and describes the angle by which you must rotate the matrix in the clockwise direction. For each , we want to count the number of cells that are different after the rotation. For example, the diagram below depicts the  rotation of a Hackonacci Matrix when :

image

As you can see, there are two cells whose values change after the rotation. Note that we filled each initial cell using the Hackonacci formula given above:

  •  
    Because this is an odd number, we mark this cell with a Y.
  •  
    Because this is an even number, we mark this cell with an X.
  •  
    Because this is an even number, we mark this cell with an X.
  •  
    Because this is an even number, we mark this cell with an X.

Given the value of  and  queries, construct a Hackonacci Matrix and answer the queries. For each query , print an integer on a new line denoting the number of cells whose values differ from the initial Hackonacci Matrix when it's rotated by  degrees in the clockwise direction.

Input Format

The first line contains two space-separated integers describing the respective values of  and 
Each line  of the  subsequent lines contains an integer denoting .

Constraints

  • It is guaranteed that each  is multiple of  degrees.

Output Format

For each , print a single integer on a new line denoting the number of different cells that differ between the initial matrix and the matrix rotated by  degrees.

Sample Input 0

4 3
90
180
270

Sample Output 0

10
6
10

Explanation 0

Because , we must build a  Hackonacci matrix and then perform  queries, shown below. The following diagrams depict each query rotation, and cells whose values changed after performing a rotation are highlighted in orange:

  1. When we perform a  rotation on the matrix, there are  cells whose values change: 
    imageThus, we print  on a new line.
  2. When we perform a  rotation on the matrix, there are  cells whose values change:image
    Thus, we print  on a new line.
  3. When we perform a  rotation on the matrix, there are  cells whose values change:image
    Thus, we print  on a new line.

题目链接:https://www.hackerrank.com/contests/w27/challenges/hackonacci-matrix-rotations


题目大意:hackerrank上的题是比poj上的题好懂,这个题就是说先定义一个类似于斐波那契数列那样的一个数列,然后形成一个二维图,在Hackonacci((i*j)^2)这个位置的数如果是奇数就是Y,偶数就是X,然后有q次询问,每次询问会可能会旋转90度,180度,270度,360度(取余),然后问你和原图有多少个地方不同。

思路:先求Hackonacci数列,你会很容易发现一个规律,规律为奇,偶,奇,偶,偶,奇,七个一循环(打个表就出来了规律),然后我就按照他的思路模拟了一遍,本以为超时,又水过了。。。现在感觉题都是水过的,终测好可啪,其实可以先把2000种情况都处理出来,先离线,应该会快一些

好吧,弄了半天hackonacci数列还是显示不出来,QAAQ


代码:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int a[3000][3000];
int main(){
    int n,p;
    while(~scanf("%d%d",&n,&p)){
        for(long long i=1;i<=n;i++){//对称
            for(long long j=1;j<=i;j++){
                if(((i*j)*(i*j))%7==0||((i*j)*(i*j))%7==1||((i*j)*(i*j))%7==3||((i*j)*(i*j))%7==6){
                    a[i][j]=1;
                    a[j][i]=1;
                }
                else{
                    a[i][j]=0;
                    a[j][i]=0;
                }
            }
        }
        int h1=0;//90度
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                if(a[i][j]!=a[j][n-i+1]){
                    h1++;
                }
            }
        }
        int h2=0;180度
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                if(a[i][j]!=a[n-i+1][n-j+1]){
                    h2++;
                }
            }
        }
        int h3=0;270度
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                if(a[i][j]!=a[n-j+1][i]){
                    h3++;
                }
            }
        }
        while(p--){
            int h;
            scanf("%d",&h);
            h%=360;
            if(h==0){
                cout<<"0"<<endl;
            }
            else if(h==90){
                cout<<h1<<endl;
            }
            else if(h==180){
                cout<<h2<<endl;
            }
            else if(h==270){
                cout<<h3<<endl;
            }
        }
    }
    return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值