Magic Sticks

#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
int main()
{
    int T, r, c;
    scanf("%d", &T);
    while (T--)
    {
        scanf("%d %d", &r, &c);
        if (min(r, c) == 1)
        {
            ull result = (max(r, c) + 1) / 2;
            printf("%I64d\n", result);
            continue;
        }
        ull x = min(r, c), y = max(r, c);
        if (y % 2)
            printf("%I64d\n", (y + 1) / 2 * x);
        else
            printf("%I64d\n", (y / 2) * x + (x / 2));
    }
}

猜你喜欢

转载自www.cnblogs.com/lv-anchoret/p/9382329.html