[c++]代码库
#include <stdio.h>
#define NODES 6
int graph[6][6]={
{0,0,1,1,0,0},
{0,0,0,0,1,0},
{0,0,0,0,0,1},
{0,0,0,0,0,1},
{0,0,0,0,0,1},
{0,0,0,0,0,0},};
int result[6];
int i=0;
void setline(int line) {
for (int i=0;i<NODES;i++) {
graph[line][i]=0;
}
}
int judgecol(int col) {
for (int i=0;i<NODES;i++) {
if (graph[i][col]) {
return 0;
}
}
return 1;
}
int main() {
int isdeleted[NODES]={0,0,0,0,0,0};
while (!isdeleted[0]||!isdeleted[1]||!isdeleted[2]||!isdeleted[3]||!isdeleted[4]||!isdeleted[5]) {
int node;
if (judgecol(0)&&!isdeleted[0]) node=0;
if (judgecol(1)&&!isdeleted[1]) node=1;
if (judgecol(2)&&!isdeleted[2]) node=2;
if (judgecol(3)&&!isdeleted[3]) node=3;
if (judgecol(4)&&!isdeleted[4]) node=4;
if (judgecol(5)&&!isdeleted[5]) node=5;
setline(node);
isdeleted[node]=1;
printf("%d ",node+1);
//if (judgecol(0)&&judgecol(1)&&judgecol(2)&&judgecol(3)&&judgecol(4)&&judgecol(5)) break;
}
return 0;
}
by: 发表于:2018-05-28 15:25:35 顶(0) | 踩(0) 回复
??
回复评论