2013年11月16日

UVa 12673 - Football

#include <cstdio>
#include <algorithm>

struct S {
  int s1, s2;
  bool operator < (const S & other) const {
    return (s1 - s2) > (other.s1 - other.s2);
  }
} s[100000];

int main() {
  int N, G;
  while (scanf("%d%d", &N, &G) == 2) {
    for (int i = 0; i < N; i++) {
      scanf("%d%d", &s[i].s1, &s[i].s2);
    }
    std::sort(s, s + N);
    int sum = 0;
    for (int i = 0; i < N; i++) {
      int need = -(s[i].s1 - s[i].s2);
      if (need >= 0) {
        if (G > need) {
          G -= need + 1;
          need = -1;
        } else {
          need -= G;
          G = 0;
        }
      }
      sum += (need < 0) * 3 + !need;
    }
    printf("%d\n", sum);
  }
  return 0;
}

2013年11月1日

UVa 11956 - Brainfuck

#include <stdio.h>

int main() {
  int n, T = 1;
  scanf("%d\n", &n);
  char s[111111];
  while (n--) {
    gets(s);
    int i, v[100] = {}, now = 0;
    for (i = 0; s[i]; i++) {
      switch (s[i]) {
      case '>':
        now = (now + 1) % 100;
        break;
      case '<':
        now = (now + 100 - 1) % 100;
        break;
      case '+':
        v[now] = (v[now] + 1) % 256;
        break;
      case '-':
        v[now] = (v[now] + 256 - 1) % 256;
        break;
      }
    }
    printf("Case %d: ", T++);
    for (i = 0; i < 100; i++) {
      printf("%02X%s", v[i], i == 99 ? "\n" : " ");
    }
  }
  return 0;
}