Compare commits
No commits in common. "d7f5b988388c730445f658d747eb4f5ecbc42765" and "60447f6bf87d93dc7946ae5d604600e0e1557bdc" have entirely different histories.
d7f5b98838
...
60447f6bf8
63
src/main.rs
63
src/main.rs
|
|
@ -1,44 +1,43 @@
|
|||
struct Solution;
|
||||
mod arr;
|
||||
impl Solution {
|
||||
fn get_product(a: i32, b: i32) -> i32 {
|
||||
((a as i64 * b as i64) % 12345) as i32
|
||||
fn is_same(mat: &Vec<Vec<i32>>, target: &Vec<Vec<i32>>) -> bool {
|
||||
for i in 0..mat.len() {
|
||||
for j in 0..mat[i].len() {
|
||||
if mat[i][j] != target[i][j] {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
pub fn construct_product_matrix(mut grid: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
|
||||
let mut arr = vec![0; grid.len() * grid[0].len()];
|
||||
let mut ans = vec![0; grid.len() * grid[0].len()];
|
||||
for i in 0..grid.len() {
|
||||
for j in 0..grid[0].len() {
|
||||
arr[i * grid[0].len() + j] = grid[i][j];
|
||||
pub fn find_rotation(mat: Vec<Vec<i32>>, target: Vec<Vec<i32>>) -> bool {
|
||||
let mut v = vec![vec![0; mat[0].len()]; mat.len()];
|
||||
if Solution::is_same(&mat, &target) {
|
||||
return true;
|
||||
}
|
||||
for x in 1..4 {
|
||||
for i in 0..mat.len() {
|
||||
for j in 0..mat[i].len() {
|
||||
let (mut py, mut px) = (i, j);
|
||||
for _ in 0..x {
|
||||
(px, py) = (mat.len() - 1 - py, px)
|
||||
}
|
||||
v[py][px] = mat[i][j];
|
||||
}
|
||||
}
|
||||
if Self::is_same(&v, &target) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
ans[0] = arr[0];
|
||||
for i in 1..arr.len() {
|
||||
ans[i] = Solution::get_product(arr[i], ans[i - 1]);
|
||||
}
|
||||
let mut last = arr[ans.len() - 1];
|
||||
for i in (1..arr.len()-1).rev() {
|
||||
let x = arr[i];
|
||||
arr[i] = Solution::get_product(ans[i-1], last);
|
||||
last = Solution::get_product(last, x)
|
||||
}
|
||||
arr[0] = last % 12345;
|
||||
arr[ans.len() - 1] = ans[ans.len() - 2] % 12345;
|
||||
for i in 0..grid.len() {
|
||||
for j in 0..grid[0].len() {
|
||||
grid[i][j] = arr[i * grid[0].len() + j];
|
||||
}
|
||||
}
|
||||
grid
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let result = Solution::construct_product_matrix(arr::make_matrix(r#"[[1,2],[3,4]]"#));
|
||||
let result = Solution::find_rotation(
|
||||
arr::make_matrix(r#"[[1,0,0],[1,0,1],[0,0,1]]"#),
|
||||
arr::make_matrix(r#"[[0,1,1],[0,0,0],[1,1,0]]"#),
|
||||
);
|
||||
println!("{:?}", result);
|
||||
}
|
||||
/*
|
||||
[[1,4,4,0]
|
||||
,[-2,0,0,1]
|
||||
,[1,-1,1,1]]
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue