C - Darkness I

Princess Celestia, is an Alicorn pony, the former co-ruler of Equestria alongside her younger sister Princess Luna. Princess Celestia raises the sun and governs Equestria, while Princess Luna raises the moon and oversees the realm of dreams.

In early days, Luna felt overshadowed and ignored by the ponies of Equestria, who slept through her beautiful night sky. These negative emotions festered and eventually led her to be consumed by the darkness and power of the mythical creature known as Nightmare Moon.

The darkness was spreading, and could be transformed into the following model:

In an �×�n×m white 2D grid, there are several black grid points.

Every second, all white points that are 4-neighbors of at least two black points will turn black.

What is the minimum number of black points needed to turn the entire grid black in the end?

Input

The first line contains two integers, �n and �m (1≤�,�≤105)(1≤n,m≤105), representing the size of the grid.

Output

Output a single integer representing the minimum number of black points needed.

Sample 1

InputcopyOutputcopy
2 2
2

Note

One of the minimal placement schemes of the sample is shown below.

  思维题:不要只考虑对角线,多画画试试就能发现规律了->_<-

#include<iostream>
using namespace std;
#define int long long 
int N, M;
signed main()
{
	cin >> N >> M;
	if (N == 1 || M == 1)return cout << max(N, M) / 2 + 1, 0;
	else if (N == M) return cout << N, 0;
	else
		(N & 1) || (M & 1) ? cout << (N / 2 + M / 2) + 1  : cout << (N / 2 + M / 2);
	return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值