Codeforces A.Domino piling

news/2025/3/26 17:41:11/

CF小白

(水题)

最简解法(之一):

A. Domino piling

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

 题目链接如下:

Problem - 50A - Codeforces

// Domino piling
#include<stdio.h>
int main(){int M,N;int re;scanf("%d%d",&M,&N);re=(M*N)/2;printf("%d",re);
}

主要从M,N的奇偶性,考虑:

任意一边为偶数和两边都是奇数,分为两类。

任意一边为偶数:一定能铺满;两边都是奇数时:一定会空出1*1 Square的空间。

最后发现转换为int时,奇数偶数情况一样。

居然真的AC掉了!


http://www.ppmy.cn/news/906721.html

相关文章

题解 UVA11729【Commando War】

0.前言 题外话&#xff1a;UVA题目真的waiting好久啊。 1.正文 “不能同时给两个部下交代任务&#xff0c;但部下们可以同时执行他们各自的任务。” 因为如果前一位部下的执行时间较长&#xff0c;那么就可以覆盖下一位部下的部分时间&#xff0c;即可节省时间。 而如果前一…

Command 命令模式

定义 命令模式是一种数据驱动的设计模式&#xff0c;它属于行为型模式。 请求以命令的形式包裹在对象中&#xff0c;并传给调用对象。调用对象寻找可以处理该命令的合适的对象&#xff0c;并把该命令传给相应的对象&#xff0c;该对象执行命令。 命令模式使请求发送者与请求…

贪心-突击战(Commando War, UVa 11729)

题目&#xff1a; 你有n个部下&#xff0c;每个部下需要完成一项任务。第i个部下需要你花Bi分钟交待任务&#xff0c;然后他会立刻独立地、无间断地执行Ji分钟后完成任务。你需要选择交待任务的顺序&#xff0c;使得所有任务尽早执行完毕&#xff08;即最后一个执行完的任务应…

[斜率优化] 特别行动队 commando

特别行动队 【问题描述】 你有一支由 n 名预备役士兵组成的部队,士兵从 1 到 n 编号,要将他们拆分成若干特别行动队调入战场。出于默契的考虑,同一支特别行动队中队员的编号应该连续,即为形如(i, i + 1, …, i + k)的序列。 编号为 i 的士兵的初始战斗力为 xi ,一支特别行…

Java8实战-总结2

Java8实战-总结2 基础知识方法和Lambda传递代码&#xff1a;一个例子从传递方法到Lambda 基础知识 方法和Lambda Scala和Groovy等语言的实践已经证明&#xff0c;让方法等概念作为一等值可以扩充程序员的工具库&#xff0c;从而让编程变得更容易。一旦程序员熟悉了这个强大的…

Command(命令)

Command&#xff08;命令&#xff09; 行为型 对象 1 Intent_意图2 将“请求”封装成对象&#xff0c;以使用不同的请求、队列或者日志来参数化其他对象。命令模式也支持可撤销的操作 Motivation_动机3 在系统中&#xff0c;行为请求者与行为实现者通常是一种紧耦合的关系&…

I - Commando War

先读懂题意&#xff0c;先排序&#xff0c;在相加&#xff0c;贪心算法重在思路。 I - Commando War Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Description G Commando War Input: Standard Input Output: Standard …

commands(commands软件)

QQ任逍遥为什么老“badsequenceofcommands”? bad sequence of commands的意思是&#xff1a;命令的次序错误。 WINDOWS动态链接库中文件丢失会造成软件运行参数错误&#xff0c;就会造成你的这个现象。 所以很可能是你的软件运行时参数有问题&#xff0c;电脑提示bad seque…