采用“补形”的方法,将六边形补全为平行四边形,如题中所示的例子,延长边a和c使之相交,要延长多少?答案是a-1。即将原六边形补全为一个(c + a - 1)× (b + a -1)的平行四边形,只要再减去多出的部分即可。
于是n = (b + a - 1) * (c + a - 1) - 2 * ((a - 1) + 1) * (a - 1) / 2 = (b + a - 1) * (c + a - 1) - a * (a - 1);
AC CODE:
#include <iostream>
using namespace std;
int main()
{
int a, b, c, n;
while(cin >> a >> b >> c)
{
n = (b + a - 1) * (c + a - 1) - a * (a - 1);
cout << n << endl;
}
return 0;
}