對n個隨機排列的十位數,等距離取四個數字出來

2021-08-20 09:13:05 字數 1591 閱讀 5014

題目:

對n個隨機排列的十位數,等距離取四個數字出來(包括正向間隔1個距離取數、反向1個距離取數、正向2個距離取數和反向2個距離取數。間隔乙個數子,稱為1個距離,間隔2個數字,稱為2個距離。就取這兩種距離就夠了)。比如給你乙個十位數,01 02 03 07 08 09 06 05 04 10(隨機排序的),然後按照按照以上說的四種間隔取數,先做「正向間隔1個距離取數」01 03 08 06,02 07 09 05,03 08 06 04,07 09 05 10,08 06 04 01,09 05 10 02,06 04 0,1 03,05 10 02 07,04 01 03 08,10 02 07 09;再做「反向1個距離取數」10 05 09 07,04 06 08 03,05 09 07 02,06 08 03 01,09 07 02 10,08 03 01 04,07 02 10 05,03 01 04 06,02 10 05 09,01 04 06 08;再做「正向2個距離取數」01 07 06 10,02 08 05 01...........;再做「反向2個距離取數」10 06 0

**:string allsen = ;

random random = new random();

//將十個數隨機排序

for(int i=0;i

int aaa = random.nextint(allsen.length);

string temp = allsen[i];

allsen[i] = allsen[aaa];

allsen[aaa] = temp;

}//       linklist linklist = new linklist();

string one = new string[4];

for(int i=0;i

system.out.println(allsen[i]);

}system.out.println("正1個");

for(int i=0;i

if(i == 0) else

int k = i;

for(int j=0;j<4;j++) else

system.out.print( one[j]);

}  system.out.println();

}system.out.println("負1個");

for(int i=allsen.length-1;i>= 0;i--)else

system.out.print( one[j]);

}  system.out.println();

}system.out.println("正2個");

for(int i=0;i

int k = i;

for(int j=0;j<4;j++) else

system.out.print( one[j]);

}  system.out.println("");

}system.out.println("負2個");

for(int i=allsen.length-1;i>=0;i--)else

system.out.print(one[j]);

}  system.out.println("");

}

平方十位數

由0 9這10個數字不重複 不遺漏,可以組成很多10位數字。這其中也有很多恰好是平方數 是某個數的平方 比如 1026753849,就是其中最小的乙個平方數。請你找出其中最大的乙個平方數是多少?include include includeusing namespace std 定義乙個判斷乙個十位...

藍橋 平方十位數

題目 由0 9這10個數字不重複 不遺漏,可以組成很多10位數字。這其中也有很多恰好是平方數 是某個數的平方 比如 1026753849,就是其中最小的乙個平方數。請你找出其中最大的乙個平方數是多少?注意 你需要提交的是乙個10位數字,不要填寫任何多餘內容。解法1 運用next permutatio...

藍橋杯 平方十位數 DFS

1.題目 由0 9這10個數字不重複 不遺漏,可以組成很多10位數字。這其中也有很多恰好是平方數 是某個數的平方 比如 1026753849,就是其中最小的乙個平方數。請你找出其中最大的乙個平方數是多少?2.解決方法 dfs 模板 3.include include include include ...