URAL 1725. Sold out! (Math AH)

Source: Internet
Author: User

Title Link: http://acm.timus.ru/problem.aspx?space=1&num=1725


Every fall, all movies is shown to a full house at one of the most popular cinema theatres in Yekaterinburg because Stude NTS 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 are small, and people constantly stumble over othe R 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'll make his and his-to-his seat. He chooses it in such a, the number of people over whose feet he'll stumble would be minimal. If These numbers is equal for the left and right ends, the visitor chooses the end of the row which was closer to his seat . Student of the Department of Philosophy Vasya is a enthusiastic movie-goer and an equally enthusiastic hater of Mathemati Cs. He was the first to buy a ticket to the first exhibition of a new movie. When Vasya entered the hall and sat down with his seat, he saw, and seats in the row were still unoccupied. Vasya knew that by the time the exhibition started the hall would is full. Therefore, quite a number of other visitors would stumble over he feet while getting to their seats. Despite his hatred for mathematics, Vasya is able to instantly estimate the maximal number of people that would stumble O Ver his feet before the exhibition. Can do the same? Inputthe only input line contains the total number of seats  NIn the row where Vasya are sitting and the number of his seat k(1≤ kN≤50; Nis even). These integers is separated with a space. The seats in the row is numbered starting with one. Outputoutput the maximal number of people who would stumble over Vasya ' s feet. Sample
input Output
4 1
1


The code is as follows:

#include <cstdio>int main () {    int n, K;    while (~SCANF ("%d%d", &n,&k))    {        int ans;        if (n = = 2)//on both sides        {            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! (Math AH)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.