Pagini recente » Cod sursa (job #3282180) | Cod sursa (job #2845592) | Cod sursa (job #2982258) | Cod sursa (job #550396) | Cod sursa (job #2254425)
#include <fstream>
#define DIM 205
using namespace std;
ifstream fin ("oras.in");
ofstream fout ("oras.out");
int n, i, j, model, mat[DIM][DIM];
int g(int x, int y)
{
int i;
if (x == y)
return 0;
g(x-2, y);
for (i=1; i<=x-2; i++){
mat[i][x] = 1;
mat[x-1][i] = 1;
}
mat[x][x-1] = 1;
return 0;
}
int main()
{
fin >> n;
if (n == 4){
fout << "-1";
return 0;
}
if (n%2 == 1){
mat[1][2] = 1;
mat[2][3] = 1;
mat[3][1] = 1;
model = 3;
} //fac matricea pt n = 3
else{
mat[1][2]=1;
mat[1][3]=1;
mat[1][5]=1;
mat[2][3]=1;
mat[2][4]=1;
mat[2][5]=1;
mat[3][4]=1;
mat[3][6]=1;
mat[4][5]=1;
mat[4][6]=1;
mat[4][1]=1;
mat[5][6]=1;
mat[5][3]=1;
mat[6][1]=1;
mat[6][2]=1;
model = 6;
//si pt n = 6
}
g(n, model); //generez plecand de la modelele generate
for (i=1; i<=n; i++){
for (j=1; j<=n; j++){
fout << mat[i][j];
}
fout << "\n";
}
return 0;
}
//ideea : adaug doua noduri, unul din care toate strazile pleaca spre nodurile initiale, si altul in care intra toate strazile (si din care pleaca un drum catre primul)