栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

I - Painting a Square

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

I - Painting a Square

SDUT 2022 Spring Team Contest(for 21) - 15 - Virtual Judge

There is a square of size a times aa×a. In its top left corner there is a square brush of size b times bb×b. You should use this brush to paint a square (you can assume that the top left corner of size b times bb×b is already painted). It is allowed to move a brush only in parallel to the square's sides. What is the minimal distance the center of the brush should pass to make the whole square painted?

Input

The input contains two integers aa and bb (1 le b le a le 10^{6}1≤b≤a≤106) — the sides of the square and the brush, correspondingly.

Output

Output a single integer — the minimal distance that should be passed by the center of the brush. It is guaranteed that the answer is an integer.

Sample 1

InputcopyOutputcopy
4 2
6

Sample 2

InputcopyOutputcopy
4 3
3

Sample 3

InputcopyOutputcopy
9 3
24

Sample 4

InputcopyOutputcopy
1000000 1
999999999999

题解:分析可得红色矩阵应当螺旋移动才能使得步数最少,而给定矩阵边长相同,在纸上模拟直接找到规律即可。

 

 

#include
using namespace std;
typedef long long ll;
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    ll tmp=a-b;
    ll ans=tmp;//初始是tmp,因为开始必须要走3个tmp,后面只用走2个
    while(tmp>0)
    {
        ans=ans+tmp+tmp;
        tmp-=b;
    }
    printf("%lldn",ans);
    return 0;
}

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/926043.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号