您的位置:首页 > 其它

codeforces 50A. Domino piling 【贪心】

2018-03-10 18:19 330 查看
time limit per test 2 seconds

memory limit per test 256 megabytes

input standard input

output standard output

You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:

Each domino completely covers two squares.

No two dominoes overlap.

Each domino lies entirely inside the board. It is allowed to touch the edges of the board.

Find the maximum number of dominoes, which can be placed under these restrictions.

Input

In a single line you are given two integers M and N — board sizes in squares (1 ≤ M ≤ N ≤ 16).

Output

Output one number — the maximal number of dominoes, which can be placed.

Examples

input

2 4

output

4

input

3 3

output

4

思路:开始想的太复杂了。。。注意条件是M<=N 所以先考虑短边的,N长所以木框纵着放放置的最多。最后如果m为奇数,再横着放木块

#include<iostream>
using namespace std;
int main()
{
int n,m;
int sum;
cin>>m>>n;
int temp1 = m/2;//M考虑为宽 N考虑为长 M边最多可以放置多少块(即多少行)
sum = temp1*n;//那么因为小木快的边长为1,则一行木块可以有N个,temp1*N 即是这些行的总数
int temp2 = m%2;
if(temp2 == 1)//如果M是奇数,那么横向放置 放置数目为N/2(小木块长度为2)
{
sum +=n/2;
}
cout<<sum<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: