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为奇数,再横着放木块
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; }
相关文章推荐
- codeforces 721B B. Passwords(贪心)
- codeforces 486c-Palindrome Transformation【贪心】
- CodeForces - 363D Renting Bikes(二分,贪心)
- Codeforces - 777B. Game of Credit Cards 贪心
- Codeforces 226D The table 贪心
- Codeforces 777E(贪心+单调栈)
- codeforces 721D Maxim and Array(贪心)
- codeforces 442C C. Artem and Array(贪心)
- Codeforces 520D. Cubes 贪心模拟
- Codeforces 578B Or Game [贪心] [位运算]
- codeforces 74B Train 贪心 简单模拟
- Codeforces 478C Table Decorations【贪心】
- C - Hacker, pack your bags! Codeforces(贪心)
- 【codeforces 337C Quiz】 + 贪心
- CodeForces - 731C Socks(并查集)(贪心)
- Codeforces 526C - Om Nom and Candies (贪心 + 思维)
- Codeforces 839B Game of the Rows (贪心)
- CodeForces - 609A USB Flash Drives ( 排序 简单贪心 )
- Codeforces 597B: Restaurant(贪心+结构体排序)
- Codeforces 534D - Handshakes (贪心 + 模拟)