File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed
Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 1+ // https://atcoder.jp/contests/abc145/tasks/abc145_c
2+ //
3+ // 以下のクレートを使用。
4+ //
5+ // - `itertools`
6+ // - `nalgebra`
7+ // - `proconio`
8+
9+ use itertools:: Itertools as _;
10+ use nalgebra:: { Point2 , Scalar } ;
11+ use proconio:: input;
12+ use proconio:: source:: { Readable , Source } ;
13+
14+ use std:: convert:: Infallible ;
15+ use std:: io:: BufRead ;
16+ use std:: marker:: PhantomData ;
17+
18+ fn main ( ) {
19+ // `proconio::input!`。
20+ //
21+ // https://docs.rs/proconio/0.3.6/proconio/macro.input.html
22+ input ! {
23+ n: usize ,
24+ points: [ ReadPoint2 <f64 >; n] ,
25+ }
26+
27+ // nC2通りの組み合わせを列挙するのに`<_ as itertools::Itertools>::tuple_combinations`を用いる。
28+ // また各点同士の距離√((x_i - x_j)^2 + (y_i - y_j)^2)を求めるのに`nalgebra::distance`を使う。
29+ //
30+ // https://docs.rs/itertools/0.8/itertools/trait.Itertools.html#method.tuple_combinations
31+ // https://docs.rs/nalgebra/0.19/nalgebra/fn.distance.html
32+ let ans = 2.0 / ( n as f64 )
33+ * points
34+ . into_iter ( )
35+ . tuple_combinations ( )
36+ . map ( |( p1, p2) | nalgebra:: distance ( & p1, & p2) )
37+ . sum :: < f64 > ( ) ;
38+ println ! ( "{}" , ans) ;
39+ }
40+
41+ // `proconio::source::Readable`を実装することで`Usize1`のようなマーカー型を作ることができる。
42+ //
43+ // https://docs.rs/proconio/0.3.6/proconio/source/trait.Readable.html
44+
45+ struct ReadPoint2 < T > ( Infallible , PhantomData < fn ( ) -> T > ) ;
46+
47+ impl < N : Readable < Output = N > + Scalar > Readable for ReadPoint2 < N > {
48+ type Output = Point2 < N > ;
49+
50+ fn read < R : BufRead , S : Source < R > > ( source : & mut S ) -> Point2 < N > {
51+ Point2 :: new ( N :: read ( source) , N :: read ( source) )
52+ }
53+ }
Original file line number Diff line number Diff line change @@ -142,6 +142,13 @@ url = "https://atcoder.jp/contests/abc144/tasks/abc144_d"
142142matching = { FloatOr = { abs = 1e-6 , rel = 1e-6 } }
143143meta = { using = [" libm" , " proconio" ] }
144144
145+ [examples .abc145-c ]
146+ type = " Normal"
147+ name = " ABC145: C - Average Length"
148+ url = " https://atcoder.jp/contests/abc145/tasks/abc145_c"
149+ matching = { FloatOr = { abs = 1e-6 , rel = 1e-6 } }
150+ meta = { using = [" itertools" , " nalgebra" , " proconio" ] }
151+
145152[examples .abc150-d ]
146153type = " Normal"
147154name = " ABC150: D - Semi Common Multiple"
You can’t perform that action at this time.
0 commit comments