@proech
11 / 11 / 2
Регистрация: 10.07.2013
Сообщений: 150
|
29.03.2014, 16:01
|
|
метод северо западного угла (внимание костыли) )
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
| #include <stdio.h>
#include <Windows.h>
#include <iostream>
#include <locale.h>
class Element{
public:
mutable int Delivery;
mutable int Value;
Element()
{
this->Delivery = 0;
this->Value = 0;
}
static int FindMinElement( int &a, int &b){
if(a>b)return b;
if(a==b){return a;}
else return a;
}
void SetDelivery(int a,int b)
{
this->Delivery = Element::FindMinElement(a,b);
}
};
void SetColor(int Background,int ForeGround){
void *Handle = GetStdHandle((DWORD)-11);
SetConsoleTextAttribute(Handle,(WORD)(Background<<4|ForeGround));
}
int main(int ArgCount,char**Arguments){
setlocale(0,"");
int i = 0;
int j = 0;
int n=0;
int m=0;
SetColor(0,9);
std::cout<<"Введите количество A\n";
std::cin>>n;
int *a = new int [n];
std::cout<<"Введите количество B\n";
std::cin>>m;
int *b = new int[m];
Element **C = new Element* [n];
for (int i = 0;i<n;i++)
{
C[i] = new Element[m];
}
std::cout<<"Введите a[i]\n";
for (i = 0;i<n;i++){
std::cin>>a[i];
}
std::cout<<"Введите b[j]\n";
for (j=0;j<m;j++){
std::cin>>b[j];
}
SetColor(0,15);
std::cout<<"Введите C[i][j]";
for (i = 0;i<n;i++){
for (j=0;j<m;j++){
std::cin>>C[i][j].Value;
}
}
i = 0;j = 0;
while(i<n && j<m){
if (a[i]==0){i++;}
if (b[j]==0){j++;}
C[i][j].SetDelivery(a[i],b[j]);
a[i]-=C[i][j].Delivery;
b[j]-=C[i][j].Delivery;
}
for (i = 0;i<n;i++){
for (j=0;j<m;j++){
std::cout<<C[i][j].Value<<"("<<C[i][j].Delivery<<")";
}
std::cout<<std::endl;
}
int ResultFunction = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++)
{
ResultFunction += (C[i][ j].Value * C[i][j].Delivery);
}
}
std::cout<<"Опорный план найден , и равен = "<<ResultFunction;
system("pause>>void");
} |
|
1
|