当前位置: 首页 > 工具软件 > Bookworm > 使用案例 >

URAL 1638. Bookworm

冉弘化
2023-12-01

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;
}


 类似资料:

相关阅读

相关文章

相关问答