Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
こんにちは私は配列の要素を数えることによって行列のサイズを計算する必要があります。たとえば、リストに25個の要素がある場合、行列に列= 5と行5を取得する必要があります。26個の要素、5列、6行などに感謝します。
正確な要件はわかりませんが、スペースをあまり浪費しない正方行列を作成したい場合は、
int x = Math.Floor(Math.Sqrt(num_elems)); int y; if (x*x == num_elems) { y = x; } else { y = x+1; if (x*y < num_elems) { ++x; } }
行と列の数がnum_elems要素を保持できる最大1つだけ異なる、最小の行列の次元を生成します。
num_elems