Advertisement
Glebzok

SRS_factories_new

May 16th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <locale.h>
  3.  
  4. #define MAX 100
  5.  
  6. typedef struct Fac{
  7.     int chc;
  8. } Fac;
  9.  
  10. typedef struct Sol{
  11.     double s;
  12.     int chc;
  13. } Sol;
  14.  
  15. void tableoutput1(double* Array, int n, int m, char c);
  16. void tableoutput2(Sol* a, int n, int m);
  17.  
  18. int main(){
  19.     setlocale(LC_ALL, "RUS");
  20.     int n;//number of companies
  21.     int m;//number of resources
  22.     int mm;
  23.     double H[MAX][MAX];//
  24.     Sol S[MAX][MAX];//final profit
  25.     Fac st[MAX];
  26.     printf("Number of concerns:\n");
  27.     scanf("%d", &n);
  28.     printf("Number of resourses:\n");
  29.     scanf("%d", &m);
  30.     int i;
  31.     int int_tmp;
  32.     double double_tmp;
  33.     int j;
  34.     for (j = 0; j < n; j++)
  35.     {
  36.         printf("Charge from (1, ... , %d) resources  from the %d concern:\n", m, j + 1);
  37.         for (i = 1; i <= m; i++)
  38.         {
  39.             scanf("%lf", &double_tmp);
  40.             H[i][j] = double_tmp;
  41.         }
  42.         H[0][j] = 0;
  43.         S[0][j].s = 0;
  44.         S[0][j].chc = 0;
  45.     }
  46.     tableoutput1(&H[0][0], n, m, 'H');
  47.     for (i = 0; i <= m; i++)
  48.     {
  49.         S[i][0].s = H[i][n - 1];
  50.         S[i][0].chc = i;
  51.  
  52.     }
  53.     double smax;
  54.     int k, kmax;
  55.     printf("\n Selection of conditional optimal control:\n");
  56.     for (int j = 1; j < n; j++)
  57.     {
  58.         printf("From %d concerns and folowing\n", n - j);
  59.         printf("___________________\n");
  60.         printf("|  y|y-x  x|   S%d  |\n", n - j);
  61.         for (i = 1; i <= m; i++)
  62.         {
  63.             smax = S[i][j - 1].s;
  64.             kmax = 0;
  65.             for (k = 0; k <= i; k++)
  66.             {
  67.                 float gh = (H[k][n - j - 1] + S[i - k][j - 1].s);
  68.                 printf("___________________\n");
  69.                 if (k == 0)
  70.                     printf("|%3d|%3d%3d|%7.3lf|\n", i, i - k, k, gh);
  71.                 else
  72.                     printf("|   |%3d%3d|%7.3lf|\n", i - k, k, gh);
  73.                 if (gh >= smax)
  74.                 {
  75.                     smax = H[k][n - j - 1] + S[i - k][j - 1].s;
  76.                     kmax = k;
  77.                 }
  78.             }
  79.             printf("___________________\n");
  80.             printf("\n");
  81.             S[i][j].s = smax;
  82.             S[i][j].chc = kmax;
  83.         }
  84.         printf("\n\n");
  85.     }
  86.     tableoutput2(S, n, m);
  87.     mm = m;
  88.     st[n - 1].chc = S[m][n - 1].chc;
  89.     for (i = n - 1; i > 0; i--)
  90.     {
  91.         m -= st[i].chc;
  92.         st[i - 1].chc = (S[m][i - 1]).chc;
  93.     }
  94.     int chc;
  95.     printf("\n");
  96.     for (i = 1; i <= n; i++)
  97.     {
  98.         chc = st[i - 1].chc;
  99.         printf("You should invest %d resources to %d concern\n", chc, i);
  100.     }
  101.     printf("\nEarned profit: %lf", S[mm][n - 1]);
  102.     getchar();
  103.     getchar();
  104.     return 0;
  105. }
  106.  
  107. void tableoutput1(double* a, int n, int m, char f){
  108.     printf("\n Table of values of income functions:");
  109.     int i, j;
  110.     printf("\n________");
  111.     for (i = 0; i < n; i++)
  112.         printf("_________");
  113.     printf("\n|  x   |");
  114.     for (i = 0; i < n; i++)
  115.         printf("  %c%d(x) |", f, i + 1);
  116.     for (j = 0; j <= m; j++)
  117.     {
  118.         printf("\n________");
  119.         for (i = 0; i < n; i++)
  120.             printf("_________");
  121.         printf("\n");
  122.         printf("|%3d   |", j);
  123.         for (i = 0; i < n; i++)
  124.         {
  125.             printf("%7.3lf |", *(a + j * MAX + i));
  126.         }
  127.     }
  128.     printf("\n________");
  129.     for (i = 0; i < n; i++)
  130.         printf("_________");
  131.     printf("\n");
  132. }
  133.  
  134. void tableoutput2(Sol* a, int n, int m)
  135. {
  136.     printf("\n Table of values of charge and conditional optional control:");
  137.     int i, j;
  138.     printf("\n________");
  139.     for (i = 0; i < n; i++)
  140.         printf("_____________");
  141.     printf("\n|  y   |");
  142.     for (i = 0; i < n; i++)
  143.         printf("  S*%d(y) x* |", i + 1);
  144.     for (j = 0; j <= m; j++)
  145.     {
  146.         printf("\n________");
  147.         for (i = 0; i < n; i++)
  148.             printf("_____________");
  149.         printf("\n");
  150.         printf("|%3d   |", j);
  151.         for (i = 0; i < n; i++)
  152.         {
  153.             printf("%7.3lf %3d |", (*(a + j * MAX + i)).s, (*(a + j * MAX + i)).chc);
  154.         }
  155.     }
  156.     printf("\n________");
  157.     for (i = 0; i < n; i++)
  158.         printf("_____________");
  159.     printf("\n");
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement