Quantcast
Channel: C#タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9555

p49 Fence Repair(C#)

$
0
0
自分(正解) using System; public class Program { public static void Main() { int N = 3; int[] L = { 8, 5, 8 }; int first_back; int second_back; int answer = 0; List<int> L_list = new List<int>(L); while (L_list.Count > 1) { L_list.Sort(); L_list.Reverse(); first_back = L_list[L_list.Count - 1]; second_back = L_list[L_list.Count - 2]; answer += first_back + second_back; L_list.RemoveAt(L_list.Count - 1); L_list.RemoveAt(L_list.Count - 1); L_list.Add(answer); } Console.WriteLine("答え:{0}", answer); } } 解答 今回は合っていたが、貪欲法を考えるときにいかに早くルールに気付けるかが鍵になってきそう。 今回のを例でいうと、「一番短い板の節点とその次に短い板の節点は兄弟といてよい」にあたる。

Viewing all articles
Browse latest Browse all 9555

Trending Articles