Example #1
0
void solve(int casei)
{
  int N = 0;
  char eventtype = ' ';
  patient patients[100000];
  int deleted[100000] = {0};
  int nowpatents = 0;
  printf("Case #%d:\n", casei);

  scanf("%d\n", &N);
  while(N--)
  {
    scanf("%c ", &eventtype);
    if( 'P' == eventtype )
    {
      int t0 = 0, s0 = 0, r = 0;
      patient newp;
      scanf("%d %d %d\n", &t0, &s0, &r);
      newp.s = s0 - r*t0;
      newp.r = r;
      patients[nowpatents++] = newp;
    }
    else if( 'A' == eventtype )
    {
      int i = 0;
      int t = 0;
      int maxi = -1;
      int newpatients = 0;
      scanf("%d\n", &t);
      current_time = t;
      for(i = 0;i < nowpatents;++i)
        if( 0 == deleted[i] )
        {
          patients[newpatients] = patients[i];
          deleted[newpatients] = 0;
          if( (maxi < 0) || pcomp(patients[maxi], patients[newpatients]) )
            maxi = newpatients;
          newpatients++;
        }
      printf("%lld %d\n", patients[maxi].s+(patients[maxi].r)*(long long int)t, patients[maxi].r);
      deleted[maxi] = 1;
      nowpatents = newpatients;
    }
  }
}
Example #2
0
void report_summary(summary * s, summary * o, bool full)
{
  FILE *F = NULL;
  int i, newplayers = 0;
  faction *f;
  char zText[MAX_PATH];

  if (full) {
    sprintf(zText, "%s/parteien.full", basepath());
  } else {
    sprintf(zText, "%s/parteien", basepath());
  }
  F = fopen(zText, "w");
  if (!F) {
    perror(zText);
    return;
  }
#ifdef SUMMARY_BOM
  else {
    const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
    fwrite(utf8_bom, 1, 3, F);
  }
#endif
  log_info("writing summary to file: parteien.\n");
  fprintf(F, "%s\n%s\n\n", game_name(), gamedate2(default_locale));
  fprintf(F, "Auswertung Nr:         %d\n\n", turn);
  fprintf(F, "Parteien:              %s\n", pcomp(s->factions, o->factions));
  fprintf(F, "Einheiten:             %s\n", pcomp(s->nunits, o->nunits));
  fprintf(F, "Spielerpopulation:     %s\n", pcomp(s->playerpop, o->playerpop));
  fprintf(F, " davon bewaffnet:      %s\n", pcomp(s->armed_men, o->armed_men));
  fprintf(F, " Helden:               %s\n", pcomp(s->heroes, o->heroes));

  if (full) {
    fprintf(F, "Regionen:              %d\n", listlen(regions));
    fprintf(F, "Bewohnte Regionen:     %d\n", s->inhabitedregions);
    fprintf(F, "Landregionen:          %d\n", s->landregionen);
    fprintf(F, "Spielerregionen:       %d\n", s->regionen_mit_spielern);
    fprintf(F, "Landspielerregionen:   %d\n", s->landregionen_mit_spielern);
    fprintf(F, "Orkifizierte Regionen: %d\n", s->orkifizierte_regionen);
    fprintf(F, "Inaktive Vulkane:      %d\n", s->inactive_volcanos);
    fprintf(F, "Aktive Vulkane:        %d\n\n", s->active_volcanos);
  }

  for (i = 0; i < MAXRACES; i++) {
      if (i != RC_TEMPLATE && i != RC_CLONE && s->factionrace[i]) {
          const race *rc = get_race(i);
          if (rc && playerrace(rc)) {
              fprintf(F, "%13s%s: %s\n", LOC(default_locale, rc_name(rc, NAME_CATEGORY)),
                  LOC(default_locale, "stat_tribe_p"), pcomp(s->factionrace[i],
                  o->factionrace[i]));
          }
      }
  }

  if (full) {
    fprintf(F, "\n");
    {
      struct language *plang = s->languages;
      while (plang != NULL) {
        struct language *olang = o->languages;
        int nold = 0;
        while (olang && olang->locale != plang->locale)
          olang = olang->next;
        if (olang)
          nold = olang->number;
        fprintf(F, "Sprache %12s: %s\n", locale_name(plang->locale),
          rcomp(plang->number, nold));
        plang = plang->next;
      }
    }
  }

  fprintf(F, "\n");
  if (full) {
    for (i = 0; i < MAXRACES; i++) {
      if (s->poprace[i]) {
          const race *rc = get_race(i);
          fprintf(F, "%20s: %s\n", LOC(default_locale, rc_name(rc, NAME_PLURAL)),
          rcomp(s->poprace[i], o->poprace[i]));
      }
    }
  } else {
      for (i = 0; i < MAXRACES; i++) {
          if (i != RC_TEMPLATE && i != RC_CLONE && s->poprace[i]) {
              const race *rc = get_race(i);
              if (playerrace(rc)) {
                  fprintf(F, "%20s: %s\n", LOC(default_locale, rc_name(rc, NAME_PLURAL)),
                      rcomp(s->poprace[i], o->poprace[i]));
              }
          }
      }
    }

  if (full) {
    fprintf(F, "\nWaffen:               %s\n", pcomp(s->waffen, o->waffen));
    fprintf(F, "Ruestungen:           %s\n",
      pcomp(s->ruestungen, o->ruestungen));
    fprintf(F, "ungezaehmte Pferde:   %s\n", pcomp(s->pferde, o->pferde));
    fprintf(F, "gezaehmte Pferde:     %s\n",
      pcomp(s->spielerpferde, o->spielerpferde));
    fprintf(F, "Schiffe:              %s\n", pcomp(s->schiffe, o->schiffe));
    fprintf(F, "Gebaeude:             %s\n", pcomp(s->gebaeude, o->gebaeude));

    fprintf(F, "\nBauernpopulation:     %s\n", pcomp(s->peasants, o->peasants));

    fprintf(F, "Population gesamt:    %d\n\n", s->playerpop + s->peasants);

    fprintf(F, "Reichtum Spieler:     %s Silber\n",
      pcomp(s->playermoney, o->playermoney));
    fprintf(F, "Reichtum Bauern:      %s Silber\n",
      pcomp(s->peasantmoney, o->peasantmoney));
    fprintf(F, "Reichtum gesamt:      %s Silber\n\n",
      pcomp(s->playermoney + s->peasantmoney,
        o->playermoney + o->peasantmoney));
  }

  fprintf(F, "\n\n");

  newplayers = update_nmrs();

  for (i = 0; i <= NMRTimeout(); ++i) {
    if (i == NMRTimeout()) {
      fprintf(F, "+ NMR:\t\t %d\n", nmrs[i]);
    } else {
      fprintf(F, "%d NMR:\t\t %d\n", i, nmrs[i]);
    }
  }
  if (age) {
    if (age[2] != 0) {
      fprintf(F, "Erstabgaben:\t %d%%\n", 100 - (dropouts[0] * 100 / age[2]));
    }
    if (age[3] != 0) {
      fprintf(F, "Zweitabgaben:\t %d%%\n", 100 - (dropouts[1] * 100 / age[3]));
    }
  }
  fprintf(F, "Neue Spieler:\t %d\n", newplayers);

  if (full) {
    if (factions)
      fprintf(F, "\nParteien:\n\n");

    for (f = factions; f; f = f->next) {
      out_faction(F, f);
    }

    if (NMRTimeout() && full) {
      fprintf(F, "\n\nFactions with NMRs:\n");
      for (i = NMRTimeout(); i > 0; --i) {
        for (f = factions; f; f = f->next) {
          if (i == NMRTimeout()) {
            if (turn - f->lastorders >= i) {
              out_faction(F, f);
            }
          } else {
            if (turn - f->lastorders == i) {
              out_faction(F, f);
            }
          }
        }
      }
    }
  }

  fclose(F);

  if (full) {
    log_info("writing date & turn\n");
    writeturn();
  }
  free(nmrs);
  nmrs = NULL;
}