,   CyberForum.ru

(posix) - C++


 
val8
: n/a
29.05.2013, 21:39     (posix) #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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <iostream>
#include <sstream>
#include <pthread.h>
#include <vector>
using namespace std;
struct thread_data
{
 int **a;
  int i;
  int n;
  int ns;
  //thread_data*prev,*next;
};
 
void* MyThreadProc(void* lpParam)//ôó*êöèÿ ïîòîê*
{
  thread_data * data = (thread_data*)lpParam;
 if(data->i!=0)
 data->i-=1;
  for (int i=0; i < data->n; i++)
  for(int j=data->i;j<data->ns;j++)
        for (int k = 0; k <data->n; k++)
 
        if((data->a)[j][k]> (data->a)[j][i]+(data->a)[i][k])
          (data->a)[j][k]= (data->a)[j][i]+(data->a)[i][k];
 
  return 0;
}
 
void floid(int amount_of_threads, int**a,int n)//ï*ð*ëëåëü**ÿ ðå*ëèç*öèÿ *ëãîðèòì* ôëîéä*(êîë-âî ïîòîêîâ, ì*òðèö*, åå ð*çìåð)
{
 vector<thread_data>data(amount_of_threads);
  int q=0;
data[q].i=0;
data[q].n=n;
  int m = n / (amount_of_threads);//ð*çáèå*èå ì*òðèöè ïî áëîê*ì
  int r = n % (amount_of_threads);
int ns=0;//ns- êîë-âî ñòðîê â áëîêå, i-*îìåð ïåðâîé ñòðîêè â áëîêå
  for(q=0;q<amount_of_threads;q++)
  {
      if(ns!=0)
  data[q].i=ns;
      if(r==0)
      { ns=ns+m;
          data[q].ns=ns;
 
      }
      else{
          ns=ns+m+1;
          data[q].ns=ns;
          r=r-1;}
          //int**z=*&a;
          data[q].a=&*a;
/*int k=0;
for(int i=data[q].i;i<data[q].ns;i++)
{
for(int j=0;j<n;j++)
data[q].a[k][j]=a[i][j];
k++;}*/
 
 
 
        /*if(q==amount_of_threads-1)
          MyThreadProc(&data[q]);
 
    else*/
    //ñîçä**èå *îâîãî ïîòîê* (&threads[i], 0, thread_proc, &data[i]);
       for(int i=data[q].i;i<data[q].ns;i++)
  {cout<<endl;
      for(int j=0;j<data[q].n;j++)
      cout<<data[q].a[i][j]<<' ';}
 cout<<endl<<endl;
 }
 vector<pthread_t>threads(amount_of_threads);
 for(q=0;q<amount_of_threads;q++)
        pthread_create(&threads[q], 0, MyThreadProc, &data[q]);
for(q=0;q<amount_of_threads;q++)
  pthread_join(threads[q], 0);
 
 
 
 
 
  /*for (int q = 0; q < amount_of_threads - 1; ++q)
    CloseHandle(threads[q]);
 
  delete[] threads;
  delete[] data;*/
 
  }
 bool prov(int**a,int n)//ïðîâåðê* ** **ëè÷èå öèêëîâ îòðèö äëè**û
  {
      for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
      for(int k=0;k<n;k++)
      if(a[j][i]+a[i][k]<0)
      return false;
      return true;
  }
 
int main()
{
setlocale(0,"RUS");
thread_data x;
cout<<" n=";
cin>>x.n;
x.a=new int*[x.n];
for (int i = 0; i <x.n; i++)
x.a[i]=new int[x.n];
int p;
cout<<"êîë-âî ïîòîêîâ=";
cin>>p;
for (int i = 0; i <x.n; i++)
for (int j = 0; j < x.n; j++)
{cout<<"a["<<i<<"]["<<j<<"]=";
cin>>x.a[i][j];}
if(prov(x.a,x.n)==true)
{floid(p, x.a,x.n);
for (int i = 0; i <x.n; i++)
    {cout<<endl;
for (int j = 0; j <x.n; j++)
cout<<x.a[i][j]<<' ';}}
else
cout<<"åñòü öèêëû îòð äëè**û"<<endl;
 
    return 0;
}
/*Âõîä*ûå ä***ûå
  0 1 2 1
  2 0 7 40
  6 5 0 2
  1 50 4 0
 
Ðåçóëüò*ò
0 1 2 1
2 0 4 3
3 4 0 2
1 2 3 0*/
 :  -        .     
1 2 3
2 3 4 
5 6 7
 2-  
1 2 3 
2 3 4
   1 . 2    .  
  - 
 int q=0;
data[q].i=0;
data[q].n=n;
  int m = n / (amount_of_threads);//ð*çáèå*èå ì*òðèöè ïî áëîê*ì
  int r = n % (amount_of_threads);
int ns=0;//ns- êîë-âî ñòðîê â áëîêå, i-*îìåð ïåðâîé ñòðîêè â áëîêå
  for(q=0;q<amount_of_threads;q++)
  {
      if(ns!=0)
  data[q].i=ns;
      if(r==0)
      { ns=ns+m;
          data[q].ns=ns;
 
      }
      else{
          ns=ns+m+1;
          data[q].ns=ns;
          r=r-1;}
          //int**z=*&a;
          data[q].a=&*a;
2 10
,
Similar
41792 / 34177 / 6122
: 12.04.2006
: 57,940
29.05.2013, 21:39     (posix)
:

C++
C++
( ) C++
, C++
Posix C++
Posix C++
- , - C++
C++
C++ Getch() The POSIX name for this item is deprecated
C++ 1 error C4996: 'getche': The POSIX name for this item is deprecated
C++ ( ) - , ?
C++ ,



:
.

: 21:55. GMT +3.
- , ,
-
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
@Mail.ru