[AtCoder] ABC 130 C – Rectangle Cutting

問題

方針

長方形の重心と任意の点を結ぶ直線は長方形の面積を半分に分割します。任意の点が \( x = \dfrac{W}{2} \wedge y = \dfrac{H}{2} \) のとき、直線は \( 2 \) つ以上あり、そうではないとき、\( 1 \) つです。

コード

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll W, H, x, y;
  cin >> W >> H >> x >> y;
  double s = (double) W * H / 2.0;
  if (W % 2 == 1 || H % 2 == 1) {
    printf("%f %d", s, 0);
    return 0;
  }
  if ((H / 2 == x && W / 2 == y) || (H / 2 == y && W / 2 == x)) {
    printf("%f %d", s, 1);
  } else {
     printf("%f %d", s, 0);
  }
  return 0;
}