Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- unsigned combustibil, k, nrPersImport,nrPersInDrum;
- double distParcurs;
- typedef struct Calls
- {
- unsigned short x, y, prioritate;
- struct Calls * urm;
- }nevoiasi;
- typedef enum{Very_Low, Low, Medium, High, Very_High} prioritate;
- prioritate prio[5];
- nevoiasi *persImport[100], *persInDrum[100];
- nevoiasi * ADD_Call(nevoiasi *prim) {
- nevoiasi *q, *p;
- p = (nevoiasi *)malloc(sizeof(nevoiasi));
- printf("x= "); scanf("%hu", &p->x);
- printf("y= "); scanf("%hu", &p->y);
- printf("prioritate= "); scanf("%hu", &p->prioritate);
- prio[p->prioritate]++;
- if (p->prioritate == Very_High)
- persImport[nrPersImport++] = p;
- p->urm = NULL;
- if (prim == NULL)
- return p;
- if (prim->x >= p->x && prim->y > p->y) {
- p->urm = prim;
- return p;
- }
- q = prim;
- while (q->urm != NULL && q->urm->x <= p->x && q->urm->y < p->y)
- q = q->urm;
- p->urm = q->urm;
- q->urm = p;
- return prim;
- }
- void Afisare(nevoiasi *prim) {
- nevoiasi *q;
- q = prim;
- while (q != NULL) {
- printf("\n%d %d\n", q->x, q->y);
- q = q->urm;
- }
- }
- double Dist(nevoiasi *p, nevoiasi *q) {
- return sqrt(pow(q->x - p->x, 2) + pow(q->y - p->y, 2));
- }
- double DistPersImport() {
- unsigned i;
- double suma = 0;
- for (i = 0; i < nrPersImport - 1; i++)
- suma += Dist(persImport[i], persImport[i + 1]);
- return suma;
- }
- void SetPriority( nevoiasi *prim) {
- nevoiasi *q = prim;
- nrPersImport = 0;
- int i;
- for (i = 0; i < 5; i++)
- prio[i] = 0;
- while (q)
- {
- q->prioritate++;
- prio[q->prioritate]++;
- if (q->prioritate == Very_High)
- persImport[nrPersImport++] = q;
- q = q->urm;
- }
- }
- void PersInDrum() {
- nevoiasi *q;
- int i = nrPersImport - 2;
- while (i >= 0) {
- q = persImport[i];
- q = q->urm;
- if (k - nrPersImport - nrPersInDrum < 0)
- return;
- while (q != persImport[i+1])
- {
- if (k - nrPersImport - nrPersInDrum < 0)
- return;
- if ((persImport[i + 1]->x - persImport[i]->x)*(q->y - persImport[i]->y) == (q->x - persImport[i]->x) *(persImport[i + 1]->y - persImport[i]->y)) {
- persInDrum[nrPersInDrum++] = q;
- }
- }
- }
- }
- int main() {
- unsigned days = 1, i, n;
- nevoiasi *prim = NULL;
- printf("Numarul de pachete ce pot fi livrate: "); scanf("%u", &k);
- printf("Numarul de apeluri: "); scanf("%u", &n);
- for (i = 1; i <= n; i++)
- prim = ADD_Call(prim);
- do {
- printf("Ziua %u:\n", days);
- combustibil += 10000;
- if (prio[Very_High]) {
- distParcurs = DistPersImport();
- if ((unsigned)prio[Very_High] > k || (unsigned)distParcurs > combustibil) {
- printf("Nu se poate ajunge la toate persoanlele");
- return 0;
- }
- }
- SetPriority(prim);
- days++;
- } while (1);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment