2013年12月13日

UVa 12718 - Dromicpalin Substrings

#include <stdio.h>

int main() {
  int T, C = 1;
  scanf("%d", &T);
  while (T--) {
    char s[1111];
    scanf("%s", s);
    int i, j, ans = 0;
    for (i = 0; s[i]; i++) {
      int cnt[26] = {}, odd = 0;
      for (j = i; s[j]; j++) {
        odd += (cnt[s[j] - 'a'] & 1) ? -1 : 1;
        cnt[s[j] - 'a']++;
        ans += (odd <= 1);
      }
    }
    printf("Case %d: %d\n", C++, ans);
  }
  return 0;
}

UVa 12712 - Pattern Locker

#include <stdio.h>

int main() {
  long long mod = 1e13 + 7;
  int T, C = 1;
  scanf("%d", &T);
  while (T--) {
    int L, M, N;
    scanf("%d%d%d", &L, &M, &N);
    L *= L;
    long long i, ans = 0, sum = 1;
    for (i = 0; i < M - 1; i++) {
      sum = (sum * (L - i)) % mod;
    }
    for (; M <= N; M++) {
      sum = (sum * (L - M + 1)) % mod;
      ans = (ans + sum) % mod;
    }
    printf("Case %d: %lld\n", C++, ans);
  }
  return 0;
}

UVa 12709 - Falling Ants

#include <stdio.h>

int main() {
  int T;
  while (scanf("%d", &T) && T) {
    int L, W, H;
    int maxH = 0, maxV = 0;
    while (T--) {
      scanf("%d%d%d", &L, &W, &H);
      int v = L * W * H;
      if (H > maxH || (H == maxH && v > maxV)) {
        maxH = H;
        maxV = v;
      }
    }
    printf("%d\n", maxV);
  }
  return 0;
}