Compare commits
2 Commits
60447f6bf8
...
d7f5b98838
| Author | SHA1 | Date |
|---|---|---|
|
|
d7f5b98838 | |
|
|
f1f47604f8 |
63
src/main.rs
63
src/main.rs
|
|
@ -1,43 +1,44 @@
|
||||||
struct Solution;
|
struct Solution;
|
||||||
mod arr;
|
mod arr;
|
||||||
impl Solution {
|
impl Solution {
|
||||||
fn is_same(mat: &Vec<Vec<i32>>, target: &Vec<Vec<i32>>) -> bool {
|
fn get_product(a: i32, b: i32) -> i32 {
|
||||||
for i in 0..mat.len() {
|
((a as i64 * b as i64) % 12345) as i32
|
||||||
for j in 0..mat[i].len() {
|
|
||||||
if mat[i][j] != target[i][j] {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
pub fn find_rotation(mat: Vec<Vec<i32>>, target: Vec<Vec<i32>>) -> bool {
|
pub fn construct_product_matrix(mut grid: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
|
||||||
let mut v = vec![vec![0; mat[0].len()]; mat.len()];
|
let mut arr = vec![0; grid.len() * grid[0].len()];
|
||||||
if Solution::is_same(&mat, &target) {
|
let mut ans = vec![0; grid.len() * grid[0].len()];
|
||||||
return true;
|
for i in 0..grid.len() {
|
||||||
}
|
for j in 0..grid[0].len() {
|
||||||
for x in 1..4 {
|
arr[i * grid[0].len() + j] = grid[i][j];
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
false
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let result = Solution::find_rotation(
|
let result = Solution::construct_product_matrix(arr::make_matrix(r#"[[1,2],[3,4]]"#));
|
||||||
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