当前位置:网站首页>2022-06-29: x = {a, B, C, D}, y = {e, F, G, H}, the length of the two small arrays X and Y is 4. If yes: a + e = B + F = C + G = D + H
2022-06-29: x = {a, B, C, D}, y = {e, F, G, H}, the length of the two small arrays X and Y is 4. If yes: a + e = B + F = C + G = D + H
2022-06-30 00:48:00 【Fuda scaffold constructor's daily question】
2022-06-29:x = { a, b, c, d },
y = { e, f, g, h },
x、y The length of both small arrays is 4.
If there is : a + e = b + f = c + g = d + h,
So x and y Is a perfect pair .
The title is given N A small array , The length of each small array is K.
Back here N In small arrays , How many are perfect .
From Ali .
answer 2022-06-29:
Look for features , save map, Find the difference between adjacent numbers of the array , Assemble into key,value It's quantity .
The code to use rust To write . The code is as follows :
use std::collections::HashMap;
fn main() {
let sc: Vec<i32> = vec![5, 3, 2, 11, 21, 19, 10, 1, 20, 11, 1, 6, 15, 24, 18, 27, 36];
let mut ii: i32 = 0;
while ii < sc.len() as i32 {
let n = sc[ii as usize];
ii += 1;
let m: i32 = sc[ii as usize];
ii += 1;
let mut matrix: Vec<Vec<isize>> = vec![];
for i in 0..n {
matrix.push(vec![]);
for _ in 0..m {
matrix[i as usize].push(sc[ii as usize] as isize);
ii += 1;
}
}
println!("matrix = {:?}", matrix);
let ans = perfect_pairs(&mut matrix);
println!("ans = {}", ans);
}
}
fn perfect_pairs(matrix: &mut Vec<Vec<isize>>) -> isize {
let mut ans: isize = 0;
// key : character string features , Difference characteristics : "_5_-2_6_9"
let mut counts: HashMap<String, isize> = HashMap::new();
for arr in matrix.iter() {
let mut self0: String = String::new();
let mut minus: String = String::new();
for i in 1..arr.len() as isize {
self0.push_str(
&(String::from("_") + &format!("{}", arr[i as usize] - arr[(i - 1) as usize])),
);
minus.push_str(
&(String::from("_") + &format!("{}", arr[(i - 1) as usize] - arr[i as usize])),
);
}
ans += match counts.get(&minus) {
Some(v) => *v,
None => 0,
};
counts.insert(
self0.clone(),
match counts.get(&self0) {
Some(v) => (*v) + 1,
None => 1,
},
);
}
return ans;
}
The results are as follows :

边栏推荐
- Crmeb SMS for program configuration of knowledge payment system
- [garment software] what are the criteria for the selection of garment production management system?
- TwinCAT 3 EL7211模塊控制倍福伺服
- TwinCAT 3 el7211 module controls Beifu servo
- Go out and protect yourself
- [mrctf2020]ezpop-1 | PHP serialization
- 玉米地里的小鸟
- 阿于的彩虹桥
- How to design test cases
- [programming problem] maze problem
猜你喜欢

Intermittent sampling and forwarding interference

How to create a module in the idea and how to delete a module in the idea?

解决choice金融终端Excel/Wps插件修复visual basic异常

岁月不饶人

如何在IDEA中自定义模板、快速生成完整的代码?

Solve the problem of repairing Visual Basic exceptions with excel/wps plug-in of choice financial terminal

Yunna | how to use the system to manage fixed assets? How to manage fixed assets?

MySQL advanced 1

Yunna | fixed assets system management, NC system management where are the fixed assets

Too voluminous ~ eight part essay, the strongest king of interview!
随机推荐
Good test / development programmers vs. average programmers
Ml: introduction to confidence interval (the difference and relationship between precision / accuracy / accuracy), use method, and detailed introduction to case application
Live broadcast configuration of crmeb knowledge payment system program configuration (method 2)
The third bullet of wechat payment app application for refund
Developers, why does the maturity of container technology herald the arrival of cloud native era?
玉米地里的小鸟
如何在IDEA中自定义模板、快速生成完整的代码?
岁月不饶人
如何在IDEA中自定義模板、快速生成完整的代碼?
Initial i/o and its basic operations
Interviewer: how to solve the problem of massive requests for data that does not exist in redis, which affects the database?
利用huggingface进行文本分类
MySQL deadlock
Netease cloud music beta music social app "mus" matches friends of the same frequency through music
Yunna | fixed assets information system management, information-based fixed assets management
【three.js】WEB3D初次体验
Which securities company is better and which platform is safer for stock speculation account opening
传统微服务框架如何无缝过渡到服务网格 ASM
【Proteus仿真】8位端口检测8独立按键
Lower expectations