CodeForces - 50A Domino piling (贪心+递归)
CodeForces - 50A Domino piling (贪心+递归)
题意分析
奇数*偶数=偶数,如果两个都为奇数,最小的奇数-1递归求解,知道两个数都为1,返回0。
代码
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#define INF 0x3f3f3f3f
#define nmax 200
#define MEM(x) memset(x,0,sizeof(x))
using namespace std;
int n,m;
int solve(int n,int m)
{
if(n ==1 && m == 1) return 0;
if(n%2 == 0) return n/2 * m;
else if( m%2 ==0) return m/2 *n;
else{
if(n>=m) return solve(n-1,m) + solve(1,m);
else return solve(n,m-1) + solve(n,1);
}
}
int main()
{
//freopen("in.txt","r",stdin);
while(scanf("%d%d",&n,&m) != EOF){
printf("%d\n",solve(n,m));
}
return 0;
}