競æããã°ã©ãã³ã°ã®ããã® C# ï¼4.0 以éï¼ ã® Tips è©°ãåãã
ãã®è¨äºã¯ãCompetitive Programming Advent Calendar Div2013 - PARTAKE ã®10æ¥ç®ã®è¨äºã§ãã
ã¯ããã«
é·ãå¹´æãçµã¦ãã¤ãã«TopCoderã® C# ç°å¢ãã.NET Framework 2.0 ãã .NET Framework 4.0 ã¸ã¨ã¢ããã°ã¬ã¼ãããã¾ããã
ããã§ãã£ãã TopCoder ã® æ¬çª SRM ã§ä½¿ç¨ããè¨èªã C++ ãã C# ã¸ã¨å¤æ´ãã¾ãããã¾ããããã¾ã§ç«¶æããã°ã©ãã³ã°ã§æ©è§£ãç³»ã®ã³ã³ãã¹ã㧠C# ã使ã£ããã¨ãã»ã¨ãã©ãªãã£ããããåå¿é²ã¨ãã¦æ¬ããã°ã§SRMã®éå»åã C# 4.0 ã§è§£ãããã«ãã¾ããã
æ¬è¨äºã§ã¯ãéå»åã解ãéç¨ã§å¾ãã競æããã°ã©ãã³ã°åãã®ç°¡å㪠C⯠ã®å°æãã¾ã¨ãã¦ãã¾ãã
Câ¯4.0 ãå©ç¨ã§ãããªã³ã©ã¤ã³ã¸ã£ãã¸
æ¨æºã©ã¤ãã©ãªã«ãããã¼ã¿æ§é ç³»ã®ã¯ã©ã¹
åºæ¬çã« System.Collections.Generic
ã§å®ç¾©ããã¦ããã¸ã§ããªãã¯ã³ã¬ã¯ã·ã§ã³ã¯ã©ã¹ã使ãã¾ãã
System.Collections
ã«å®ç¾©ããã¦ããArrayList
ãªã©ã®éã¸ã§ããªãã¯ã¯ã©ã¹ã¯éå»ã®éºç©ã®ãã使ãã¾ããã
// ããã«ãªã³ã¯ãªã¹ã System.Collections.Generic.LinkedList<T> // STLã® list ã«ç¸å½ // ãªã¹ã System.Collections.Generic.List<T> // STLã® vector ã«ç¸å½ // ãã¥ã¼ System.Collections.Generic.Queue<T> // STLã® queue ã«ç¸å½ // ã¹ã¿ã㯠System.Collections.Generic.Stack<T> // STLã® stack ã«ç¸å½ // è¾æ¸ System.Collections.Generic.SortedDictionary<TKey,TValue> // STLã® map ã«ç¸å½ System.Collections.Generic.Dictionary<TKey,TValue> // ãã¼ã§ä¸¦ã³æ¿ããããªãã SortedDictionary ããé«é // éå System.Collections.Generic.SortedSet<T> // STLã® set ã«ç¸å½ System.Collections.Generic.HashSet<T> // ãã¼ã§ä¸¦ã³æ¿ããããªãã SortedSet ããé«é // å¤åé·æ´æ° System.Numerics.BigInteger // è¤ç´ æ° System.Numerics.Complex // STLã® complex<double> ã«ç¸å½
System.Numerics
ã使ç¨ã§ããç°å¢ï¼TopCoder)ã§ã¯å¤åé·æ´æ°ãè¤ç´ æ°ãå©ç¨ã§ãã¾ãã
ä¾å¤ã§ãªã¼ãã¼ããã¼ãã§ãã¯
æ´æ°å士ã®æ¼ç®ã«ãªã¼ãã¼ããã¼ãçºçããã¨ãããã®ã¾ã¾å¦çãç¶è¡ããã¦å ¨ãéãã¨ããã§ã¨ã©ã¼ãçºçããããã¯ããªã¼ãã¼ããã¼çºçæã§ä¾å¤ãçºçããã»ãã便å©ã§ãã
ãã㧠C⯠ã«ã¯ããªã¼ãã¼ããã¼ãçºçããã¨ãã« OverflowException
ãçºçããã checked ãã¼ã¯ã¼ããããã¾ãã
int x = int.MaxValue; int y = checked(x + 1); // â OverFlowException
ãã ããé¢æ°ã®å é¨ã§ã®ãªã¼ãã¼ããã¼ã«ã¤ãã¦ã¯æ¤ç¥ãã¾ããã
static int overflow() { int x = int.MaxValue; return x + 1; } static void Main(string[] args){ int y = checked(overflow()); // overflowé¢æ°å ã§ãªã¼ãã¼ããã¼ãã¦ãä¾å¤ã¯çºçããªãã }
ã¾ãããã® checked ãã¼ã¯ã¼ãã使ããªãã¦ããã³ã³ãã¤ã«ãªãã·ã§ã³ã® /checked
ã使ç¨ããã¨ããã©ã«ãã§ã³ã¼ãå
¨åã®ãªã¼ãã¼ããã¼ãã§ãã¯ãæå¹ã«ãªãã¾ãã
Visual Studio 2012 ã使ã£ã¦ããå ´åã¯ã
ããã¸ã§ã¯ãã®ããããã£âããã«ããã¿ãâ詳細è¨å®ãã¿ã³âãæ¼ç®ã®ãªã¼ãã¼ããã¼ããã³ã¢ã³ãã¼ããã¼ã®ãã§ãã¯ãã«ãã§ãã¯ãå
¥ããã¨æå¹ã«ãªãã¾ãã
å®éã«ãªã¼ãã¼ããã¼ããã¦ãä¾å¤ãçºçããã¨ãã®æ¨æºã¨ã©ã¼åºåã以ä¸ã®ããã«ãªãã¾ããã©ãã§ãªã¼ãã¼ããã¼ãèµ·ããããã®ãä¸ç®çç¶ã§ããã
ãã³ãã«ããã¦ããªãä¾å¤: System.OverflowException: ç®è¡æ¼ç®ã®çµæãªã¼ãã¼ããã¼ãçºçãã¾ããã å ´æ LittleElephantAndString.getNumber(String A, String B) å ´æ d:\Topcoder\LittleElephantAndString.cs:è¡ 41 å ´æ LittleElephantAndStringHarness.runTestCase(Int32 casenum__) å ´æ d:\Topcoder\LittleElephantAndString.cs:è¡ 117 å ´æ LittleElephantAndStringHarness.run_test(Int32 casenum) å ´æ d:\Topcoder\LittleElephantAndString.cs:è¡ 70 å ´æ LittleElephantAndString.Main(String[] args) å ´æ d:\Topcoder\LittleElephantAndString.cs:è¡ 49
ãã ãæµ®åå°æ°ç¹åã®å ´åã¯ãªã¼ãã¼ããã¼ä¾å¤ãçºçããªãã®ã§æ³¨æãã¦ãã ããã
LINQ
é åã«å¯¾ããç°¡åãªæä½ãéè¨ã«ã¤ãã¦ã¯ãLINQ ã®ã¡ã½ããã使ãã¨ç°¡æ½ã«æ¸ãã¾ãã
ãããã®ã¡ã½ããã¯ãIEnumerable<T> ã«å¯¾ãã¦å®ç¾©ããã¦ããããããããå®è£
ãã¦ãã
List<T>
Queue<T>
Stack<T>
SortedDictionary<TKey,TValue>
Dictionary<TKey,TValue>
SortedSet<T>
HashSet<T>
String
ãªã©ããã使ç¨ãããã¨ãã§ãã¾ãã
// using System.Linq; ãã¦ããã㨠var empty = new int[] {}; var a1533 = new int[] { 1, 5, 3, 3 }; /* æå¤§å¤ */ a1533.Max(); // â 5 empty.Max(); // â InvalidOperationException empty.DefaultIfEmpty(-1).Max(); // â -1 (空ã®å ´å㯠-1 ãè¿ã) /* æå°å¤ */ a1533.Min(); // â 1 empty.Min(); // â InvalidOperationException empty.DefaultIfEmpty(-1).Min(); // â -1 (空ã®å ´å㯠-1 ãè¿ã) /* åè¨å¤ */ a1533.Sum(); // â 12 empty.Sum(); // â 0 /* å¹³å */ a1533.Average(); // â 3.0 empty.Average(); // â InvalidOperationException empty.DefaultIfEmpty(-1).Average(); // â -1 (空ã®å ´å㯠-1 ãè¿ã) /* éé */ a1533.Reverse().ToArray(); // â { 3, 3, 5, 1 } /* ãã£ã«ã¿ */ a1533.Where(s => s < 4).ToArray(); â // { 1, 3, 3 } /* åå(map) */ a1533.Select(s => s * 2).ToArray(); // â { 2, 10, 6, 6 } /* åå&å¹³å¦å (concatMap) */ a1533.SelectMany(s => new[] { s, s }).ToArray(); // â { 1, 1, 5, 5, 3, 3, 3, 3 } /* ãã¼ã¸ */ a1533.Zip(new int[] { 1, 2, 1, 2 }, (a, b) => a + b).ToArray(); // { 2, 7, 4, 5} /* éè¤åé¤ */ a1533.Distinct().ToArray(); // â { 1, 5, 3 } /* æåã®è¦ç´ */ a1533.First(); // â 1 empty.First(); // â InvalidOperationException empty.FirstOrDefault(); // â 0 ï¼ç©ºã®å ´åã¯ä¾å¤ãæããã®ã§ã¯ãªããã®åã®åæå¤ãè¿ãï¼ /* æå¾ã®è¦ç´ */ a1533.Last(); // â 3 empty.Last(); // â InvalidOperationException empty.LastOrDefault(); // â 0 ï¼ç©ºã®å ´åã¯ä¾å¤ãæããã®ã§ã¯ãªããã®åã®åæå¤ãè¿ãï¼ /* æåã®è¦ç´ ï¼é·ããï¼ã§ãªãå ´åã¯ä¾å¤ãæããï¼ */ a1533.Single(); // â InvalidOperationException empty.Single(); // â InvalidOperationException a1533.SingleOrDefault(); // â InvalidOperationException empty.SingleOrDefault(); // â 0 ï¼ç©ºã®å ´åã¯ä¾å¤ãæããã®ã§ã¯ãªããã®åã®åæå¤ãè¿ãï¼ /* X çªç®ã®è¦ç´ */ a1533.ElementAt(1); // 5 a1533.ElementAt(99); // â ArgumentOutOfRangeException a1533.ElementAtOrDefault(99); // â 0ï¼ç¯å²å¤ã®å ´åã¯ä¾å¤ãæããã®ã§ã¯ãªããã®åã®åæå¤ãè¿ãï¼ /* å é ããè¦ç´ ãåå¾ */ a1533.Take(1).ToArray(); // â { 1 } /* å é ããè¦ç´ ãã¹ããã */ a1533.Skip(1).ToArray(); // â { 5, 3, 3 } /* å é ããæ¡ä»¶ãæºããè¦ç´ ãåå¾ */ a1533.TakeWhile(s => s == 1).ToArray(); // â { 1 } /* å é ããæ¡ä»¶ãæºããè¦ç´ ãã¹ããã */ a1533.SkipWhile(s => s == 1).ToArray(); // â { 5, 3, 3 } /* å®å®ã½ã¼ã */ a1533.OrderBy(s => s).ToArray(); // â { 1, 3, 3, 5} a1533.OrderByDescending(s => s).ToArray(); // â { 5, 3, 3, 1} /* è¦ç´ ãå ¨ã¦æ¡ä»¶ãæºããã¦ããããå¤å® */ a1533.All(s => s % 2 == 1); // â true /* æ¡ä»¶ãæºããè¦ç´ ãåå¨ããããå¤å® */ a1533.Any(s => s % 2 == 0); // â false /* æ¡ä»¶ãæºããè¦ç´ ã®åæ° */ a1533.Where(s => s == 3).Count(); // â 2 a1533.Count(s => s == 3); // â 2 /* é åã空ã§ã¯ãªãããå¤å® */ a1533.Any(); // â true empty.Any(); // â false
LINQ ã«ã¤ãã¦ã¯ã¯ã¨ãªæ§æãé
延èªã¿è¾¼ã¿ãªã©ãä»ã«ãç¥ãã¹ãç¥èãããã®ã§ãããããã§ã¯æ·±è¿½ããã¾ããã
ä½åº¦ãå®è¡ãããç®æã§ã¯ LINQ ã¡ã½ãã ã¯ä½¿ç¨ããªã
LINQ ã§å®ç¾©ããã¦ããé¢æ° ã¯ã¨ã¦ã便å©ã§ããããã¤ã¼ãã«æ¸ããããã ãã¶é度ãé
ãã®ã§æ³¨æããå¿
è¦ãããã¾ãã
é«ã
100000 åå¼ã¶ã ããªããç¹ã«åé¡ãªãã®ã§ãã 1000000åããããè¶
ãã㨠TLE ã®å±éºãããã¾ãã
ä¸è¨ã®ã³ã¼ãã¯
Math.Max
ã 1000ä¸åå®è¡ããã¨ãã«ãããæéEnumerable.Max
ã 1000ä¸åå®è¡ããã¨ãã«ãããæéArray.Length
ã 1000ä¸åå®è¡ããã¨ãã«ãããæéEnumerable.Count
ã 1000ä¸åå®è¡ããã¨ãã«ãããæé
ãè¨ããã³ããã¼ã¯ã§ãã
Math.Max : 24ms Enumerable.Max : 1363ms Array.Length : 8ms Enumerable.Count: 218ms
ãããè¦ã¦åããã¨ãããåç´ãªå¦çã§ãä½åº¦ãå¼ã³åºãããã¨æéãé常ã«ããããã¨ããããã¾ãã
ç¹ã« TopCoder ã§ã¯ 1ååãè¶
ããã¨ã¾ã TLE ã§ãã
ç®å®ã¨ã㦠100ä¸å以ä¸å¼ã°ãããç®æã§ã¯ LINQ ã使ç¨ããªãããã«ãã¾ãããã
é åã®åæå
// æ¨æºçãªé åçæ var array = new int[] {0, 3, 5}; // [0,1...] ã®é åãçæãã var array = Enumerable.Range(0, 4).ToArray(); // {0, 1, 2, 3} // åæå¤ãå ¨ã¦åãé åãçæãã var array = Enumerable.Repeat(-1, 4).ToArray(); // â { -1, -1, -1, -1}
è¤æ°ã®ãã¼ã§ã½ã¼ããã
OrderBy / OrderByDescending
㨠ThenBy / ThenByDescending
ã¨ä½µç¨ãããã¨ã§ãè¤æ°ã®ãã¼ã§ã½ã¼ããããã¨ãã§ãã¾ãã
以ä¸ã¯ãx ã®æé ã«ã½ã¼ããã¦ã x ãåã座æ¨ã«ã¤ãã¦ã¯ y ã®éé ã§ã½ã¼ããã¦ãã¾ãã
int[] xs = { 1 , 1, 3, 2, 5, 5 }; int[] ys = { 2, -1, 1, 2, 5, 3 }; var xy = xs.Zip(ys, (x, y) => new { x, y }) .OrderBy(p => p.x) .ThenByDescending(p => p.y) .ToArray(); // [(x,y)]={(1,2),(1,-1),(2,2),(3,1),(5,5),(5,3)}
Array.Sort
ã使ç¨ããå ´åã¯ä»¥ä¸ã®ããã«æ¸ãã¾ãã
Array.Sort
㯠OrderBy
ã使ãããï¼ï¼ï¼åéãã®ã§é度ãéè¦ããå ´åã«ä½¿ãã¾ãã
var xy = xs.Zip(ys, (x, y) => new { x, y }).ToArray(); Array.Sort(xy, (a, b) => { if (a.x != b.x) return a.x.CompareTo(b.x); return -a.y.CompareTo(b.y); });
içªç®ã¨i+1çªç®ã®è¦ç´ ã使ã£ãå¦ç
Skip 㨠Zip ãçµã¿åããã¾ãã
以ä¸ã¯ã |array[i] - array[i+1]|
ã®åè¨ãæ±ããä¾ã§ãã
var array = new[] { 0, 2, 1, 3 }; var totalDiff = array.Zip(array.Skip(1), (a0, a1) => Math.Abs(a0 - a1)).Sum(); // â 5
ç¯å²å¤ã¢ã¯ã»ã¹ã®å¿é ãããå¿ è¦ããªãã®ããããããã§ãã
座æ¨å§ç¸®
ToDictionary
ã使ãã¨ã{å¤âindex}ã®ããã·ã¥ãç°¡åã«çæã§ãã¾ãã
int[] x1 = new[] { 100, 10, 1, 10000 }; int[] x2 = new[] { 10, 10000, -555 }; var indexFromValueTable = Enumerable.Concat(x1, x2).Distinct() .OrderBy(v => v) .Select((value, index) => new { value, index }) .ToDictionary(p => p.value, p => p.index); x1 = x1.Select(v => indexFromValueTable[v]).ToArray(); // {3,2,1,4} x2 = x2.Select(v => indexFromValueTable[v]).ToArray(); // {2,4,0}
ã¡ã¢ä»ãæ¢ç´¢
null許容åã®é åã«ã¡ã¢ããã¨ã§ãé åã®è¦ç´ ãåæåããæéãçãã¾ãã
int?[,] memo = new int?[50, 50]; public int choose(int s, int t) { if (!memo[s, t].HasValue) { if (t == 0 || t == s) return 1; memo[s, t] = choose(s - 1, t - 1) + choose(s - 1, t); } return memo[s, t].Value; }
äºæ¬¡å ã¸ã£ã°é åãçæãã
Java ã§ã¯ jag = new int[h][w]
ã¨ä¸è¡ã§æ¸ããã®ã§ãããCâ¯ã§ã¯ä»¥ä¸ã®ããã«æ¸ãå¿
è¦ãããã¾ãã
var jag = new int[h][]; for (int i = 0; i < h; i++) { jag[i] = new int[w]; }
Enumerable.Repeat
ã使ãã¨ç°¡åã«æ¸ãããã§ãããããã ã¨åä¸é
åã®ã¤ã³ã¹ã¿ã³ã¹ããæ§æãããã¸ã£ã°é
åã«ãªã£ã¦ãã¾ãã¾ãã
// ééã£ãçææ¹æ³ int[][] jag = Enumerable.Repeat(new int[w], h).ToArray(); // jag[0][0] = 1; ã¨ãã㨠jag[1][0] == 1 ã«ãªãã
代ããã«Select
ãå©ç¨ãããã¨ã§æ£ããçæã§ããããã«ãªãã¾ãã
int[][] jag = Enumerable.Range(0, h).Select(_ => new int[w]).ToArray();
å¤æ¬¡å é åã®ãµã¤ãºãæ±ãã
C++ ã® vector<vector<T>>
ã¨æ··åãã¦ã縦ï¼ï¼æ¬¡å
ç®ï¼ã®é·ããæ±ããã®ã« Length ã使ãã®ã¯ééãã§ããGetLength
ã使ãã¾ãã
int[,] array = new int[3,4]; array.Length; // â 12 array.GetLength(0); // â 3 array.GetLength(1); // â 4
å¤æ¬¡å é å㧠LINQ ã使ã
å¤æ¬¡å
é
å㯠IEnumerable
ãå®è£
ãã¦ãã¾ãããIEnumerable<T>
ãå®è£
ãã¦ããªããããLINQ ã®ã¡ã½ããã使ããã¨ãã§ãã¾ããã
ããã§Cast<T>()
ã使ã£ã¦ IEnumerable<T>
ã«å¤æãããã¨ã§ãLINQ ã¡ã½ããã使ç¨ã§ããããã«ãªãã¾ãã
int[,] grid = new int[,] { { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 } }; var sequence = grid.Cast<int>().ToArray(); // â { 0, 1, 2, 3, 4, 5, 6, 7, 8} var maxValue = grid.Cast<int>().Max(); // â 8 var sumValue = grid.Cast<int>().Sum(); // â 36
æååé åãå ¨ã¦çµåãã¦ï¼ã¤ã®æååã«ãã
TopCoderã§ããããåå¦çã®ä¸ã¤ã§ãããString.Concat
ã使ãã°ä¸çºã§ãã
String.Concat(new String[] { "u" , "na" , "gi"}); // -> "unagi"
åºåãæåãå
¥ãããå ´åã¯ãString.Join
ã使ãã¾ãã
String.Join(",", new[] { "u", "na", "gi" }); // â "u,na,gi"
ã¹ãã¼ã¹åºåãã®æ°å¤ãããªãæååã int ã®é åã«ãã
String.Split
㨠LINQ 㮠Select
ãçµã¿åããã¾ãã
var s = "11 22 44"; s.Split().Select(s => int.Parse(s)).ToArray(); // -> new int[] {11,22,44} s.Split().Select(int.Parse).ToArray(); // delegate ãç´æ¥æ¸¡ããã¨ãã§ãã¾ã
æååå士ãASCIIã®è¾æ¸é ã§æ¯è¼ãã
æååãæ¯è¼ããé¢æ°ã« String.Compare
ãString.CompareTo
ãããã¾ããããã®é¢æ°ã§ã¯ASCIIè¾æ¸é æ¯è¼ã«ãªãã¾ããã
ããã¯å®è¡ç°å¢ã®ã«ã«ãã£ãå
ã«ããã®å½ã®èªç¶è¨èªã«å¿ããæ¯è¼ãè¡ãä»æ§ã ããã§ããï¼ .NET Framework で文字列を使用するためのベスト プラクティス
if('A'.CompareTo('a') < 0) // â true if("A".CompareTo("a") < 0) // â false // charåã§ã®æ¯è¼ï¼ASCII)ã¨çµæãéãï¼ï¼
ASCIIè¾æ¸é ã§æååæ¯è¼ãããå ´åã¯ã代ããã«String.CompareOrdinal
ã使ãã¾ãã
if(String.CompareOrdinal("A","a") < 0) // â true
åæ§ã®çç±ã§ãArray.Sort
ãOrderBy
ã§ã®ã½ã¼ããASCIIè¾æ¸é ã«ãªãã¾ããã
/* ASCIIè¾æ¸é æ¯è¼ã§ã¯ãªãã½ã¼ã */ var array = new[] { "a-b", "ab", "-ab", "a-c", "ac", "-ac" }; Array.Sort(array); // â array = { "ab","a-b","-ab","ac","a-c","-ac" } array = array.OrderBy(c => c).ToArray(); // â array = { "ab","a-b","-ab","ac","a-c","-ac" }
ã½ã¼ãç³»ã®é¢æ°ã«ã¯ã大æµå¼æ°ã« IComparer ã渡ããã®ã§ãããã« StringComparer.Ordinal
ã渡ãã¨ãString.CompareOrdinal
ã§æ¯è¼ãã¦ããã¾ãã
/* ASCIIè¾æ¸é æ¯è¼ã®ã½ã¼ã */ var array = new[] { "a-b", "ab", "-ab", "a-c", "ac", "-ac" }; Array.Sort(array, StringComparer.Ordinal); // â array = { "-ab","-ac","a-b","a-c","ab","ac" } array = array.OrderBy(c => c, StringComparer.Ordinal).ToArray(); // â array = { "-ab","-ac","a-b","a-c","ab","ac" }
æåå㧠i çªç®ã®æåãå¤æ´ãã
String ã¯ä¸å¤ãªãã¸ã§ã¯ãã®ãããæ·»åã¢ã¯ã»ã¹ã§è¦ç´ ãæ´æ°ãããã¨ãã§ãã¾ããã
ãã®ãããä¸æ¦ Char é
åã«ãã¦ããç·¨éãã¾ãã
string s = "unagi"; //s[1] = 's'; ãã«ãã¨ã©ã¼ï¼ Char[] array = s.ToCharArray(); // Char[] ã«å¤æ array[1] = 's'; new String(array); // æååã«å¤æ â "usagi"
åºæ°å¤æ
æ°å¤ããæååã¸ã®å¤æ㯠Convert.ToString
ãæååããæ°å¤ã¸ã®å¤æã¯ãConvert.ToInt32
, Convert.ToInt64
ã使ç¨ãã¾ãã
ãã ããæå®ã§ããåºæ°ã¯ 2, 8, 10, 16 ã®ï¼ç¨®é¡ã®ã¿ã§ãã
Convert.ToString(254, 2); // "11111110" Convert.ToString(254, 8); // "376" Convert.ToString(254, 16); // "fe" Convert.ToInt32("1111", 2); // 15 Convert.ToInt32("10", 8); // 8 Convert.ToInt32("ff", 16); // 255
é¢æ°å é¢æ°
è¨èªä»æ§ã¨ãã¦é¢æ°å é¢æ°ããã¯ãé¢æ°ã¯ãµãã¼ãããã¦ãã¾ããããããªã²ã¼ãåï¼ã©ã ãå¼ã§åããããªãã¨ãã§ãã¾ãã
var g = new int[50, 50]; int n = 10; Func<int,int> IN = x => x; Func<int,int> OUT = x => x + n; Action<int,int,int> addEdge = (from, to, cost) => { g[from, to] = cost; }; addEdge(IN(0), OUT(1), 5);
æ®å¿µãªãããTopCoderã§ã¯ Action
ãå¶éããã¦ä½¿ããªãã®ã§ãFunc
ã代ããã«ä½¿ãå¿
è¦ãæãã¾ãã
æ¨æºã©ã¤ãã©ãªã«ã¯ãªããã®
以ä¸ã«ã¤ãã¦ã¯ãèªåã§å®è£ ãã¦ããå¿ è¦ãããã¾ãã
swap / rotate
lower_bound / upper_bound / equal_range
next_permutation / prev_permutation
deque / priority_queue / multiset / multimap
__builtin_popcount / Integer.BitCount (Java)
Scanner (Java)