Hackonacci Matrix Rotations
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 :

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 aY. - :
Because this is an even number, we mark this cell with anX. - :
Because this is an even number, we mark this cell with anX. - :
Because this is an even number, we mark this cell with anX.
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:
- When we perform a rotation on the matrix, there are cells whose values change:
Thus, we print on a new line. - When we perform a rotation on the matrix, there are cells whose values change:

Thus, we print on a new line. - When we perform a rotation on the matrix, there are cells whose values change:

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;
}
本文介绍了一道关于Hackonacci矩阵及其旋转的问题,通过定义Hackonacci数列并将其应用于矩阵中,随后进行特定角度的旋转操作,分析了旋转前后矩阵的变化情况。
116

被折叠的 条评论
为什么被折叠?



