题目来源:http://poj.org/problem?id=1319
结果为0的时候输出“grid”。
实现详见代码:
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
const double eps=1e-10;
double a,b;
int grid(double x, double y) {
return (int) x * (int) y;
}
int skew(double x, double y) {
int a1 = (int) x, a2;
if ((int) (x - 0.5) == (int) x)
a2 = a1;
else a2 = a1 - 1.0;
y -= 1.0;
if (y < 0.0)return 0;
int ans = a1;
double d = sqrt(3.0) / 2.0;
for (int i = 2;; ++i) {
y -= d;
if (y < eps)break;
if (i & 1) {
ans += a1;
} else ans += a2;
}
return ans;
}
int main() {
while (cin >> a >> b) {
int ans1 = max(grid(a, b), grid(b, a)), ans2 = max(skew(a, b), skew(b, a));
if (ans1 >= ans2)
cout << ans1 << ' ' << "grid" << endl;
else
cout << ans2 << ' ' << "skew" << endl;
}
return 0;
}