URAL 1725. Sold Out!(数学啊 )
2015-03-15 09:01
344 查看
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1725
Every fall, all movies are shown to a full house at one of the most popular cinema theatres in Yekaterinburg because students like to spend their time sitting in a cosy chair and watching a movie instead
of attending lectures and seminars. Unfortunately, the distance between the rows of seats in the cinema hall is small, and people constantly stumble over other people's feet as they get to their seats before the film exhibition. Entering the hall, a visitor
chooses from which end of the row (left or right) he will make his way to his seat. He chooses it in such a way that the number of people over whose feet he will stumble will be minimal. If these numbers are equal for the left and right ends, the visitor chooses
the end of the row which is closer to his seat.
Student of the Department of Philosophy Vasya is an enthusiastic movie-goer and an equally enthusiastic hater of mathematics. He was the first to buy a ticket to the first exhibition of a new movie.
When Vasya entered the hall and sat down in his seat, he saw that other seats in the row were still unoccupied. Vasya knew that by the time the exhibition started the hall would be full. Therefore, quite a number of other visitors would stumble over his feet
while getting to their seats. Despite his hatred for mathematics, Vasya was able to instantly estimate the maximal number of people that would stumble over his feet before the exhibition. Can you do the same?
The only input line contains the total number of seats n in the row where Vasya is sitting and the number of his seat k (1 ≤ k ≤ n ≤ 50; n is even). These
integers are separated with a space. The seats in the row are numbered starting with one.
Output the maximal number of people who would stumble over Vasya's feet.
代码如下:
Every fall, all movies are shown to a full house at one of the most popular cinema theatres in Yekaterinburg because students like to spend their time sitting in a cosy chair and watching a movie instead
of attending lectures and seminars. Unfortunately, the distance between the rows of seats in the cinema hall is small, and people constantly stumble over other people's feet as they get to their seats before the film exhibition. Entering the hall, a visitor
chooses from which end of the row (left or right) he will make his way to his seat. He chooses it in such a way that the number of people over whose feet he will stumble will be minimal. If these numbers are equal for the left and right ends, the visitor chooses
the end of the row which is closer to his seat.
Student of the Department of Philosophy Vasya is an enthusiastic movie-goer and an equally enthusiastic hater of mathematics. He was the first to buy a ticket to the first exhibition of a new movie.
When Vasya entered the hall and sat down in his seat, he saw that other seats in the row were still unoccupied. Vasya knew that by the time the exhibition started the hall would be full. Therefore, quite a number of other visitors would stumble over his feet
while getting to their seats. Despite his hatred for mathematics, Vasya was able to instantly estimate the maximal number of people that would stumble over his feet before the exhibition. Can you do the same?
Input
The only input line contains the total number of seats n in the row where Vasya is sitting and the number of his seat k (1 ≤ k ≤ n ≤ 50; n is even). Theseintegers are separated with a space. The seats in the row are numbered starting with one.
Output
Output the maximal number of people who would stumble over Vasya's feet.
Sample
input | output |
---|---|
4 1 | 1 |
#include <cstdio> int main() { int n, k; while(~scanf("%d%d",&n,&k)) { int ans; if(n == 2)//两边 { ans = 0; } else if(k <= n/2) { ans = n-2-k; } else { ans = k-3; } printf("%d\n",ans); } return 0; }
相关文章推荐
- URAL 1725. Sold Out!(数学啊 )
- ural 1725. Sold Out!
- URAL 1984. Dummy Guy(数学啊)
- URAL 1820. Ural Steaks(数学啊 )
- URAL 2047 Maths (数学)
- URAL 1885. Passenger Comfort(数学啊 )
- 【Ural】1066 数学题 Garland
- URAL 1510. Order(map 数学啊)
- URAL 2067 Friends and Berries (推理,数学)
- 2012: The year software-defined networking sold out
- URAL 1727. Znaika's Magic Numbers(数学 vector)
- Sold out
- URAL 2005. Taxi for Programmers (最短路 数学啊)
- 【数学】 URAL 1294 Mars Satellites
- URAL 1981. Parallel and Perpendicular(数学 )
- URAL 1723. Sandro's Book(数学啊)
- URAL 1051 跳跳棋(孔明棋)(加强版) 数学找规律(较弱哦)
- URAL - 1964 Chinese Dialects (数学集合)
- URAL 1068. Sum (小学数学题)
- URAL - 2070 Interesting Numbers 素数打表+数学定理