Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f5a51ef

Browse files
author
ruislan
committed
solved q786
1 parent a22d86b commit f5a51ef

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

‎src/q/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ mod q778;
373373
mod q781;
374374
mod q783;
375375
mod q784;
376+
mod q786;
376377
mod q788;
377378
mod q789;
378379
mod q796;

‎src/q/q786.rs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use crate::q::Solution;
2+
3+
#[allow(unused)]
4+
impl Solution {
5+
pub fn kth_smallest_prime_fraction(arr: Vec<i32>, k: i32) -> Vec<i32> {
6+
// 方法1
7+
// 看到数据量不大,就尝试暴力一下,结果直接AC了,赶时间,先Mark,后面再来看有什么其他方法优化
8+
// AC 188ms 19.3mb 59/59
9+
let n = arr.len();
10+
let mut ans = Vec::new();
11+
for i in 0..n {
12+
for j in i + 1..n {
13+
ans.push((arr[i] as f64 / arr[j] as f64, i, j));
14+
}
15+
}
16+
ans.sort_unstable_by(|a, b| a.0.partial_cmp(&b.0).unwrap());
17+
vec![arr[ans[k as usize - 1].1], arr[ans[k as usize - 1].2]]
18+
}
19+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /