2013年8月28日

UVa 696 - How Many Knights

#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
  int R, C;
  while (scanf("%d%d", &R, &C) && R) {
    int r = min(R, C), c = max(R, C), ans;
    if (r == 1) {
      ans = c;
    } else if (r == 2) {
      ans = (c / 4) * 4;
      int remain = (c % 4) > 2 ? 2 : (c % 4);
      ans += remain * 2;
    } else {
      ans = (r / 2) * c + (r & 1) * (c / 2 + (c & 1));
    }
    printf("%d knights may be placed on a %d row %d column board.\n", ans, R, C);
  }
  return 0;
}

沒有留言:

張貼留言