Find Amir

来源:互联网 发布:ubuntu dash to dock 编辑:程序博客网 时间:2024/05/29 10:28

题目链接  http://codeforces.com/problemset/problem/804/A

A. Find Amir
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.

There are n schools numerated from 1 to n. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools i and j costs  and can be used multiple times. Help Sajjad to find the minimum cost he needs to pay for tickets to visit all schools. He can start and finish in any school.

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of schools.

Output

Print single integer: the minimum cost of tickets needed to visit all schools.

Examples
input
2
output
0
input
10
output
4
题目大意:

第一行输入n,表示有标号从1~n的n所学校,一个人想要把这n所学校转一遍,但是没两所学校之间需要门票,票价为(i+j)mod(n+1),也就是学校序号和对(n+1)取余。题目要求输出转完n所学校话费最少的钱,并输出。

解题思路:

考察逻辑思维的题:局一组例子便明白:

如果n为偶数:

1  2  3  4  5

      10  9  8  7  6

首先最大的与最小的之间买一张门票(1和10    2和9......),票价为0,。然后最大的和最小的之间买一张门票(10和2    9和3   8和4......),每张票价1,达到最小。

如果n为偶数的话,自己可以画画,其实差不多。

代码:

#include<iostream>using namespace std;int main(){    int n;    while(cin>>n)    {        if(n%2==0)            cout<<n/2-1<<endl;        else            cout<<n/2<<endl;    }    return 0;}