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