,   CyberForum.ru

- C++

 
ViTeK_F
: n/a
29.05.2012, 00:49     #1
. : , , ( ).

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <windows.h>
#include <locale.h>
#define inf 999
#define m 20
 
int n,a,b,t,g;
int i,j,k,l;
int smg[m][m];
int c[m] ;   // *îìåð õîä*, ** êîòîðîì ïîñåù*åòñÿ âåðøè**
int path[m]; // *îìåð* ïîñåù*åìûõ âåðøè*
int v0;    // **÷*ëü**ÿ âåðøè**
 
void prnt(void)
{
int p;
        for ( p = 0 ; p<m ; p++)
         printf("%d ", path[p] ) ;
    printf("%d ", path[0] ) ;
    printf("\n") ;
}
 
//ïîäïðîãð*ìì* **õîæäå*èÿ ã*ìèëüòî*îâ* öèêë*
int gamilton ( int k)
{
int v,q1=0;
    for(v=0; v<n && !q1; v++){
        if(smg[path[k-1]][v]){
            if (k==n &&  v==v0 ) q1=1;
            else if (c[v]==-1) {
                  c[v] = k ; path[k]=v; 
                  q1=gamilton (k+1) ;
                  if (!q1) c[v]=-1;  
                 } else continue;
        } 
    }   
    return q1;
}
 
int main()
{ 
const char *szLocale=setlocale(LC_CTYPE,"russian_Russia.1251");
 
 
FILE *fptr,*fpt; 
fptr = fopen("input.txt","r");
fpt = fopen("output.txt","w");
if(fptr == NULL) {printf(" ô*éë input.txt *å îòêðûâ*åòñÿ "); return -1;}
g=0;
// ×òå*èå èç ô*éë*
 
if(fscanf(fptr,"%d",&n)==0){
printf("Îøèáê* ââîä*");
fprintf(fpt,"Îøèáê* ââîä*");
return -1;
} // ×èñëî âåðøè*
if(n<=0)
{
printf("Îøèáê* ââîä*");
fprintf(fpt,"Îøèáê* ââîä*");
return -1;
} 
if(feof(fptr)) return -1;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{ if(fscanf(fptr,"%d",&smg[i][j])!=1)
{
printf("Îøèáê* ââîä*");
fprintf(fpt,"Îøèáê* ââîä*");
return -2;
} // Ì*òðèö* ñìåæ*îñòè
else
if(smg[i][j]<0)
{
printf("Îøèáê* ââîä*");
fprintf(fpt,"Îøèáê* ââîä*");
return -3;
 
} 
}
// Âûâîä Ì*òðèöû 
printf("  "); 
for(i=0;i<n;i++) printf("  |%3d",i);
printf("\n");
for(i=0;i<n;i++) printf("--------");
printf("\n");
for(i=0;i<n;i++){
for(j=0;j<n;j++)
if(j==0)
printf("%3d | %3d ",i,smg[i][j]);
else
printf("| %3d ",smg[i][j]);
printf("\n");
}
for (v0=0;v0<n;v0++){ 
        for(j=0;j<n;j++) c[j]=-1;
        path[0]=v0 ;
          c[v0]=v0;
    if(gamilton (1)) g++;
}
if (g) printf("Ïóòü ñóùåñòâóåò"); else printf("Ïóòü *å ñóùåñòâóåò");
    fclose(fpt);
return 0;
}
Similar
41792 / 34177 / 6122
: 12.04.2006
: 57,940
29.05.2012, 00:49    
:

C++
. C++
- () C++
C++
() C++
C++
C++
C++ ?



:
.

: 04:41. GMT +3.
- , ,
-
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
@Mail.ru