English 中文(简体)
java阵列,vert
原标题:java array with vertices of dodecahedron
  • 时间:2010-12-15 06:20:26
  •  标签:
  • java
  • arrays

我需要创建一系列阵列。

int x[][] = new int[20][3];

where the indexes of x are the vertices of a dodecahedron(just labeled 0-19 since the dodecahedron has 20 vertices), and the elements of x[0-19] are the neighbor vertices. If this is not clear take this sample:

    int y[][] = {{ 1,  5,  4}, { 0,  7,  2}, { 1,  9,  3}, { 2, 11,  4},
                 { 3, 13,  0}, { 0, 14,  6}, { 5, 16,  7}, { 1,  6,  8},
                 { 7,  9, 17}, { 2,  8, 10}, { 9, 11, 18}, {10,  3, 12},
                 {19, 11, 13}, {14, 12,  4}, {13,  5, 15}, {14, 19, 16},
                 { 6, 15, 17}, {16,  8, 18}, {10, 17, 19}, {12, 15, 18}};

在这种样本阵列中,y [0][0-2]指向外围0,即1,4。 根据这一规定,y? contain 页: 1

我只想在这个阵列中写字,而我想随意写一下。

最佳回答

如果你想在保持dec异构体结构的同时,以“占支配地位”的方式重新编号vert号,那么就应当做到:

    int[] shuffle = // an array containing a permutation of [0..19]
    int[][] z = new int[20][];
    for (int i = 0; i < 20; i++) {
        int[] vy = y[i];
        int[] vz = new int[3];
        for (int j = 0; j < 3; j++) {
            vz[j] = shuffle[vy[j]];
        }
        z[shuffle[i]] = vz;
    }
问题回答

Create the initial one, like you did, and then start shuffleing it. (lets call it int[][]x -- because you named it it x and y)

随机选择两个不同的对口,并冲淡这两个对口,多次重复。

If to swap two edges, you have to swap the arrays, as well as the "references" in the arrays. for example: swap edge 1 and 10: psydo code:

int[] temp = x[1];
x[1] = x[10];
x[10] = temp;

for (int i = 0; i < 20; i++) {
  for(int k = 0; k < 3; k++) {
    if (x[i][k]==1) {
       x[i][k]= 10;
    } else if(x[i][k]==10) {
       x[i][k]= 1;
    }
  }
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...