Codeforces 50A(往矩形里填多米诺骨牌)

探讨如何在给定尺寸的矩形板上放置尽可能多的标准2x1多米诺骨牌,确保每块骨牌完全覆盖两个方格且不重叠。
部署运行你感兴趣的模型镜像
A. Domino piling
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:

1. Each domino completely covers two squares.

2. No two dominoes overlap.

3. 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


题目大意:

输入MxN大小的矩形,已知多米诺骨牌大小为2x1(可以看做M行N列,多米诺牌大小占2行1列)。求能往矩形里放最多多米诺牌的数量是多少?

解题思路:

令a=M/2,a表示一列里可以放的多米诺牌数量;令sum=a*N,sum表示N列中放的多米诺牌的总数;如果是奇数行,则还需判断最后一行中可放入

多米诺牌的数量,将其加入sum即可求得最多米诺牌总数。


代码实现

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;


int main() {
    int N, M;                                                             //表示N行M列
    int sum=0,a=0;

    while (~scanf("%d%d", &N, &M)) {
        a = N / 2;                                                       //一列里可以放的塔罗牌数
        sum = a * M;                                                 // 乘上总列数
        if (N % 2 == 1)                                              //如果奇数行
            sum += M / 2;                                           //加上这一行中牌的数量
        printf("%d\n", sum);
    }

    return 0;
}

您可能感兴趣的与本文相关的镜像

HunyuanVideo-Foley

HunyuanVideo-Foley

语音合成

HunyuanVideo-Foley是由腾讯混元2025年8月28日宣布开源端到端视频音效生成模型,用户只需输入视频和文字,就能为视频匹配电影级音效

### Codeforces与ICPC的相关比赛和资源 Codeforces 是一个知名的在线编程竞赛平台,它不仅提供常规的算法竞赛,还特别支持国际大学生程序设计竞赛(ICPC)相关的活动。以下是关于 Codeforces 和 ICPC 的关联及其相关资源的具体说明: #### 1. **Codeforces上的ICPC官方赛事** Codeforces 定期举办由 ICPC 认可的比赛,这些比赛通常被称为 **ICPC Training Contests** 或者直接作为区域赛的一部分。这类比赛旨在帮助参赛选手熟悉 ICPC 的题目风格并提升团队协作能力[^1]。 ```python # 查询Codeforces上ICPC相关比赛的方法 import requests def fetch_icpc_contests(): url = "https://codeforces.com/api/contest.list" response = requests.get(url).json() icpc_contests = [ contest for contest in response['result'] if 'icpc' in (contest.get('name', '').lower()) ] return icpc_contests print(fetch_icpc_contests()) ``` #### 2. **Codeforces Gym 中的 ICPC 题目集合** Codeforces 提供了一个名为 **Gym** 的模块,其中包含了大量历史 ICPC 比赛的题目集。用户可以通过参与这些虚拟比赛来模拟真实的 ICPC 赛事环境,从而更好地准备正式比赛[^2]。 - 这些题目涵盖了从基础到高级的各种难度级别。 - 用户可以加入特定的 ICPC 历史比赛房间,体验完整的比赛流程。 #### 3. **ICPC Teams and Practice Resources** 除了比赛本身,Codeforces 还提供了许多辅助资源用于个人或团队训练: - **Team Collaboration Tools**: 支持多人在同一账户下提交代码,方便团队成员之间的沟通与合作。 - **Algorithm Tutorials**: 平台上有丰富的教程文档,涉及动态规划、图论等多个领域,有助于加深对复杂问题的理解。 #### 4. **社区互动和支持** 通过 Codeforces 社区论坛,参与者能够与其他热爱 ICPC 的程序员交流心得、讨论难题解决方案。这种活跃的学习氛围对于提高解决问题的能力至关重要[^1]。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值