URAL 1638. Bookworm

23 篇文章 0 订阅

1638. Bookworm

Time limit: 1.0 second
Memory limit: 64 MB
Petya bought a 100-volume edition of Advice of Veterans of Programming Contests and hoped that the succession of his failures would come to an end. He mounted a bookshelf on the wall and put the volumes onto the shelf in increasing order from left to right closely to each other. But Petya didn't know that inside the first sheet of one of the volumes there lived a mathematical worm, which was infinitely small and very voracious. The worm started to gnaw its way through the volumes perpendicularly to the sheets. It stopped upon reaching the last sheet of another volume. The following day Petya discovered the damage and became interested in how many millimeters the worm had gnawed.

Input

The first line contains 4 positive integers not exceeding 100 and separated by a space: the thickness of each volume (without the covers taken into account), the thickness of each book-cover, the number of the volume from which the worm started its route, and the number of the volume where it stopped.

Output

Output the length of the worm's route.

Sample

inputoutput
10 1 1 2
2
Problem Author: Alex Samsonov
Problem Source: XIII Open USU Championship




解析:从第c本书的正文最后一页(不包括封面)出发,到第d本书的第一页(不包括封面)结束。

c <= d:直接计算。

c > d:起始位置和终止位置刚好相反。




AC代码:

#include <bits/stdc++.h>
using namespace std;

int main(){
    int a, b, c, d;
    while(scanf("%d%d%d%d", &a, &b, &c, &d) != EOF){
        int ans = 0;
        if(c <= d) ans = (d - c - 1) * (a + 2 * b) + 2 * b;   //多啃了两个封面
        else ans = (c - d + 1) * (a + 2 * b) - 2 * b;     //两边的封面未啃
        printf("%d\n", ans);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值