We have n black points and n white points with their x values. If we connect each black point with a white point by wire. Which algorithm will cause the lowest wire needed.
# | User | Rating |
---|---|---|
1 | tourist | 3845 |
2 | jiangly | 3707 |
3 | Benq | 3630 |
4 | orzdevinwang | 3573 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | jqdai0815 | 3532 |
8 | ecnerwala | 3501 |
9 | gyh20 | 3447 |
10 | Rebelz | 3409 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 171 |
2 | adamant | 163 |
3 | awoo | 161 |
4 | maroonrk | 152 |
4 | nor | 152 |
6 | -is-this-fft- | 151 |
7 | TheScrasse | 148 |
8 | atcoder_official | 146 |
9 | Petr | 145 |
10 | pajenegod | 144 |
We have n black points and n white points with their x values. If we connect each black point with a white point by wire. Which algorithm will cause the lowest wire needed.
Name |
---|
What about kruskal?
What are values? It sounds like the Hungarian algorithm.
integers I think i found the answer, with greedy algorithm, o(nlogn).
Suppose we have a sorted list of the white point positions and the black point positions. Then we should match the i-th white dot with the i-th black dot.
I meant: what do "values" represent?
I guess your algorithm isn't correct but first, please explain what values are.
Ok, so points are on the line? Not on the plane? Then yep, greedy works.
But the greedy doesn't make a true solution in sample input : (0,2) (1,4) (3,5) dist = 7
A better solution could be: (1,2) (3,4) (1,5) dist = 6
Once you used
0,1,3
as the first set and once you used1,1,3
.