Unfortunately we were unable to fully decode your file, as it is not encoded in UTF-8.
You can try to decode it yourself by downloading it here.
#include <stdio.h> #include <stdlib.h> #include <string.h> #define ISNUMERIC(x) (x >= '0' && x <= '9') #define COMPFUNC int getInt() { static char num[12]; int n = 0; int c; for(c = getchar(); !ISNUMERIC(c); c = getchar()); num[n++] = c; for(c = getchar(); ISNUMERIC(c); c = getchar()){ num[n++] = (char) c; } num[n] = 0; return atoi(num); } typedef struct PotworS{ int id; int dmg; int hpBalance; int heal; struct PotworS *next; }Potwor; int compPotwor (const void * a, const void * b) { if ( ((Potwor *)a)->heal < ((Potwor *)b)->heal ) return 1; if ( ((Potwor *)a)->heal > ((Potwor *)b)->heal ) return -1; if( ((Potwor *)a)->dmg < ((Potwor *)b)->dmg ) return -1; return 1; } int main(int argc, char **argv) { int nPotwor; int hp; int totalBalance; Potwor *potwory; Potwor *lastPot; Potwor *tmp; Potwor rozwiazanie; Potwor *rozwEnd; nPotwor = getInt(); hp = getInt(); totalBalance = hp; potwory = new Potwor[nPotwor + 1]; memset(potwory,0,sizeof(Potwor) * (nPotwor+1)); lastPot = potwory; rozwEnd = &rozwiazanie; for(int i=1;i<=nPotwor;++i){ ++lastPot; lastPot->id = i; lastPot->dmg = getInt(); // roznica hp przed i po walce lastPot->heal = getInt(); lastPot->hpBalance = lastPot->heal - lastPot->dmg; totalBalance += lastPot->hpBalance; } if(totalBalance < 0){ // Za duze obrazenia, za malo eliksirow :( printf("NIE"); }else{ // Sortuj� lastPot = potwory + 1; qsort(lastPot,nPotwor,sizeof(Potwor),compPotwor); // Tworz� powi�zania listy lastPot = potwory; lastPot->next = lastPot + 1; for(int i=0;i<nPotwor;++i){ ++lastPot; lastPot->next = lastPot + 1; } lastPot->next = NULL; // Rozwiazuje zadanie for(int i=0;i<nPotwor;++i){ lastPot = potwory->next; tmp = potwory; // Szukam potwora do zabicia while(lastPot != NULL && lastPot->dmg >= hp){ tmp = lastPot; lastPot = lastPot->next; } if(lastPot == NULL){ // Brak potwora ktorego moge zabic :( printf("NIE"); delete potwory; return 0; } // Zabijam i pije eliksir hp += lastPot->hpBalance; tmp->next = lastPot->next; rozwEnd->next = lastPot; rozwEnd = lastPot; } printf("TAK\n"); for(Potwor *i=rozwiazanie.next;i != NULL; i = i->next) printf((i->next != NULL ? "%d " : "%d"),i->id); } delete potwory; return 0; }
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 | #include <stdio.h> #include <stdlib.h> #include <string.h> #define ISNUMERIC(x) (x >= '0' && x <= '9') #define COMPFUNC int getInt() { static char num[12]; int n = 0; int c; for(c = getchar(); !ISNUMERIC(c); c = getchar()); num[n++] = c; for(c = getchar(); ISNUMERIC(c); c = getchar()){ num[n++] = (char) c; } num[n] = 0; return atoi(num); } typedef struct PotworS{ int id; int dmg; int hpBalance; int heal; struct PotworS *next; }Potwor; int compPotwor (const void * a, const void * b) { if ( ((Potwor *)a)->heal < ((Potwor *)b)->heal ) return 1; if ( ((Potwor *)a)->heal > ((Potwor *)b)->heal ) return -1; if( ((Potwor *)a)->dmg < ((Potwor *)b)->dmg ) return -1; return 1; } int main(int argc, char **argv) { int nPotwor; int hp; int totalBalance; Potwor *potwory; Potwor *lastPot; Potwor *tmp; Potwor rozwiazanie; Potwor *rozwEnd; nPotwor = getInt(); hp = getInt(); totalBalance = hp; potwory = new Potwor[nPotwor + 1]; memset(potwory,0,sizeof(Potwor) * (nPotwor+1)); lastPot = potwory; rozwEnd = &rozwiazanie; for(int i=1;i<=nPotwor;++i){ ++lastPot; lastPot->id = i; lastPot->dmg = getInt(); // roznica hp przed i po walce lastPot->heal = getInt(); lastPot->hpBalance = lastPot->heal - lastPot->dmg; totalBalance += lastPot->hpBalance; } if(totalBalance < 0){ // Za duze obrazenia, za malo eliksirow :( printf("NIE"); }else{ // Sortuj� lastPot = potwory + 1; qsort(lastPot,nPotwor,sizeof(Potwor),compPotwor); // Tworz� powi�zania listy lastPot = potwory; lastPot->next = lastPot + 1; for(int i=0;i<nPotwor;++i){ ++lastPot; lastPot->next = lastPot + 1; } lastPot->next = NULL; // Rozwiazuje zadanie for(int i=0;i<nPotwor;++i){ lastPot = potwory->next; tmp = potwory; // Szukam potwora do zabicia while(lastPot != NULL && lastPot->dmg >= hp){ tmp = lastPot; lastPot = lastPot->next; } if(lastPot == NULL){ // Brak potwora ktorego moge zabic :( printf("NIE"); delete potwory; return 0; } // Zabijam i pije eliksir hp += lastPot->hpBalance; tmp->next = lastPot->next; rozwEnd->next = lastPot; rozwEnd = lastPot; } printf("TAK\n"); for(Potwor *i=rozwiazanie.next;i != NULL; i = i->next) printf((i->next != NULL ? "%d " : "%d"),i->id); } delete potwory; return 0; } |