当前位置:网站首页>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
- Outsourcing work for three years, waste a step confused
- Exercise "product": self made colorful Prompt string display tool (for loop and if condition judgment)
- 2022 6 月25 日交易总结
- Video to image -cv2 Videocapture() usage
- Modbus TCP RTU protocol chart
- 手写C语言之函数的嵌套调用和链式访问
- 开发者,为什么说容器技术的成熟预示着云原生时代的到来?
- Visual Studio 2017 无法打开包括文件: “QOpenGLFunctions_3_3_Core”: No such file or directory
猜你喜欢

如何做好测试用例设计

MySQL advanced 2
![[lorawan node application] the application and power consumption of Anxin ra-08/ra-08h module in lorawan network](/img/5d/9cff7bd25841c1ca6e5ab8e2994f51.png)
[lorawan node application] the application and power consumption of Anxin ra-08/ra-08h module in lorawan network

In 2022, the latest and most detailed idea associated database method and visual operation of database in idea (including graphic process)

The third bullet of wechat payment app application for refund

初始I/O及其基本操作

Interviewer: why does database connection consume resources? I can't even answer.. I was stunned!

利用huggingface进行文本分类

A Yu's Rainbow Bridge

岁月不饶人
随机推荐
@Bugs caused by improper use of configurationproperties
Common interview questions for network workers: Telnet, TTL, router and switch
CSV文件格式——方便好用个头最小的数据传递方式
浮点数通信
MySQL advanced 1
测试用例设计方法之等价类划分方法
Good test / development programmers vs. average programmers
MySQL deadlock
在线SQL转CSV工具
C语言课设心得之“推箱子”课设作品开源分享
Yunna | advantages of fixed assets system management, what are the characteristics of fixed assets management system
[mrctf2020]ezpop-1 | PHP serialization
[MRCTF2020]Ezpop-1|php序列化
Go out and protect yourself
视频转图像-cv2.VideoCapture()用法
[concurrent programming] if you use channel to solve concurrency problems?
How to design test cases
【PHP】php压测,报错:通常每个套接字地址(协议/网络地址/端口)只允许使用
Command line Basics
Arlo felt lost