Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

Alx09 May 20th, 2020 1,276 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. unsigned  k, nrPersImport, nrPersInDrum;
  6. double distParcurs, combustibil;
  7.  
  8. typedef struct Calls
  9. {
  10.     unsigned short x, y, prioritate;
  11.     struct Calls *urm;
  12.  
  13. }nevoiasi;
  14. typedef enum { Very_Low, Low, Medium, High, Very_High } prioritate;
  15. prioritate prio[5];
  16. nevoiasi *persImport[100], *persInDrum[100];
  17.  
  18. void ADD_Call(nevoiasi *prim) {
  19.     nevoiasi *q, *p;
  20.     p = (nevoiasi *)malloc(sizeof(nevoiasi));
  21.     printf("x= "); scanf("%hu", &p->x);
  22.     printf("y= "); scanf("%hu", &p->y);
  23.     printf("prioritate= "); scanf("%hu", &p->prioritate);
  24.     p->urm = NULL;
  25.     q = prim;
  26.  
  27.     while (q->urm != NULL && q->urm->x < p->x)
  28.         q = q->urm;
  29.         while (q->urm != NULL && q->urm->x == p->x && q->urm->y < p->y)
  30.         q = q->urm;
  31.    
  32.     p->urm = q->urm;
  33.     q->urm = p;
  34. }
  35. void Afisare(nevoiasi *prim) {
  36.     nevoiasi *q;
  37.     q = prim->urm;
  38.     while (q != NULL) {
  39.         printf("\n%d %d\n", q->x, q->y);
  40.         q = q->urm;
  41.     }
  42. }
  43.  
  44. double Dist(nevoiasi *p, nevoiasi *q) {
  45.     return sqrt(pow(q->x - p->x, 2) + pow(q->y - p->y, 2));
  46. }
  47.  
  48.  
  49. double SetPriority(nevoiasi *prim) {
  50.     nevoiasi *q = prim->urm, *p = prim, *t = prim;
  51.     nrPersImport = 0;
  52.     int i;
  53.     double dist = 0;
  54.     for (i = Very_Low; i <= Very_High; i++)
  55.         prio[i] = 0;
  56.     persImport[nrPersImport++] = prim;
  57.     while (q)
  58.     {
  59.  
  60.         prio[q->prioritate]++;
  61.         if (q->prioritate == Very_High) {
  62.             if (dist + Dist(p, q) + Dist(prim, q) <= combustibil) {
  63.                 dist += Dist(p, q);
  64.                 p = q;
  65.                 persImport[nrPersImport] = t;
  66.                 nrPersImport++;
  67.             }
  68.         }
  69.         t = q;
  70.         q = q->urm;
  71.     }
  72.     return dist + Dist(prim, p);
  73. }
  74. void GrowPriority(nevoiasi *prim) {
  75.     nevoiasi *q = prim->urm;
  76.     while (q)
  77.     {
  78.         if (q->prioritate < Very_High)
  79.             q->prioritate ++;
  80.         q = q->urm;
  81.     }
  82. }
  83.  
  84. void DeleteCall(nevoiasi *p) {
  85.     nevoiasi *q = p->urm;
  86. if(p->urm!= NULL)  
  87. p->urm = p->urm->urm;
  88.     free(q);
  89. }
  90.  
  91. void PersInDrum() {
  92.     nevoiasi *q, *t;
  93.     nrPersInDrum = 0;
  94.     int i, n = nrPersImport - 1;
  95.     for (i = 0; i < n; i++) {
  96.         q = persImport[i]->urm;
  97.         if(persImport[i] != persImport[i+1])
  98.         while (q->urm != NULL && q->urm != persImport[i+1]->urm)
  99.         {
  100.             t = q;
  101.             q = q->urm;
  102.             int a = persImport[i + 1]->urm->x - persImport[i]->urm->x;
  103.             int b = persImport[i + 1]->urm->y - persImport[i]->urm->y;
  104.             if (b * (q->x - persImport[i]->urm->x) == a * (q->y - persImport[i]->urm->y)) {
  105.                 persInDrum[nrPersInDrum] = t;
  106.                 nrPersInDrum++;
  107.             }
  108.         }
  109.     }
  110.  
  111. }
  112.  
  113. int main() {
  114.     unsigned days = 1, i, n;
  115.     nevoiasi *prim = (nevoiasi *)malloc(sizeof(nevoiasi));
  116.     prim->x = 0;
  117.     prim->y = 0;
  118.     prim->prioritate = 0;
  119.     prim->urm = NULL;
  120.     printf("Numarul de pachete ce pot fi livrate: "); scanf("%u", &k);
  121.     printf("Numarul de apeluri: "); scanf("%u", &n);
  122.     for (i = 1; i <= n; i++)
  123.         ADD_Call(prim);
  124.     do {
  125.         printf("Ziua %u:\n", days);
  126.         combustibil += 10000;
  127.         distParcurs = SetPriority(prim);
  128.  
  129.         if (prio[Very_High]) {
  130.             if (k - prio[Very_High])
  131.                 PersInDrum();
  132.             combustibil -= distParcurs;
  133.             for (i = 1; i < nrPersImport; i++)
  134.                 DeleteCall(persImport[i]);
  135.             for (i = nrPersInDrum + nrPersImport - k; i < nrPersInDrum; i++)
  136.                 DeleteCall(persInDrum[i]);
  137.             printf("\nRezumat sfarsit de zi %u:", days);
  138.             printf("\nCombustibil ramas %f\n", combustibil);
  139.             printf("Au fost livrate %u pachete\n", nrPersImport + nrPersInDrum);
  140.  
  141.         }
  142.         else
  143.             printf("test\n");
  144.         SetPriority(prim);
  145.         days++;
  146.     } while (prim->urm);
  147.     system("pause");
  148.     return 0;
  149. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top