应届生求职大礼包——阿里巴巴 应届生求职网YingJieSheng.COM
#define N 8 int randgener() {
return (rand() % 100); }
#define NEWINDEX(i) (i%N)*M + M-1-(i/N) void testPoj1() {
int a[M*N];
generate(a,a+M*N,randgener ); for (int i = 0 ; i < M;i++) {
for (int j = 0 ; j < N;j++) {
cout< cout< fill(B,B+N*M,false); for (int i =0 ; i < N*M;i++) { if (B[i] == true) { continue; } //寻找三个循环的值 迭代交换值 int index = -1; int nextindex=-1; int temp = a[i]; int temp2; index = i; B[i]=true; do { nextindex = NEWINDEX(index); if (nextindex==i) { a[i] = temp; break; } temp2 = a[nextindex]; a[nextindex] = temp; 应届生求职网http://www.yingjiesheng.com 第 31 页 共 92 页 应届生求职大礼包——阿里巴巴 应届生求职网YingJieSheng.COM B[nextindex] = true; temp = temp2; index = nextindex; }while(1);//一直旋转 } cout< for (int i = 0 ; i < N;i++) { for (int j = 0 ; j < M;j++) {