zoukankan      html  css  js  c++  java
  • Find Amir CodeForces

    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

    Note

    In the first example we can buy a ticket between the schools that costs .

    思路:只需要贪心的这样走,就一定可以花费最小,即。

    这样我们可以得出公式,ans=(N+1)/2-1

     

    我的AC代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <queue>
    #include <stack>
    #include <map>
    #include <set>
    #include <vector>
    #define rep(i,x,n) for(int i=x;i<n;i++)
    #define repd(i,x,n) for(int i=x;i<=n;i++)
    #define pii pair<int,int>
    #define pll pair<long long ,long long>
    #define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
    #define MS0(X) memset((X), 0, sizeof((X)))
    #define MSC0(X) memset((X), '', sizeof((X)))
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define gg(x) getInt(&x)
    using namespace std;
    typedef long long ll;
    inline void getInt(int* p);
    const int maxn=1000010;
    const int inf=0x3f3f3f3f;
    /*** TEMPLATE CODE * * STARTS HERE ***/
    
    int main()
    {
        ll n;
        cin>>n;
        ll ans=(n+1)/2-1;
        cout<<ans<<endl;
        return 0;
    }
    
    inline void getInt(int* p) {
        char ch;
        do {
            ch = getchar();
        } while (ch == ' ' || ch == '
    ');
        if (ch == '-') {
            *p = -(getchar() - '0');
            while ((ch = getchar()) >= '0' && ch <= '9') {
                *p = *p * 10 - ch + '0';
            }
        }
        else {
            *p = ch - '0';
            while ((ch = getchar()) >= '0' && ch <= '9') {
                *p = *p * 10 + ch - '0';
            }
        }
    }

    本博客为本人原创,如需转载,请必须声明博客的源地址。 本人博客地址为:www.cnblogs.com/qieqiemin/ 希望所写的文章对您有帮助。
  • 相关阅读:
    OWIN系列之自己动手编写中间件
    Visual Studio2015使用tinyfox2.x作为Owin Host调试教程
    CentOS7下自定义目录安装mono+jexus教程
    TinyFox/Jexus如何正确使用配置文件
    CentOS7下默认目录安装mono+jexus教程
    CentOS 7 常用命令
    javascript动态创建script,并监听onload、onerror
    javascript if
    StackExchange.Redis常用API
    EF EntityState的几种状态
  • 原文地址:https://www.cnblogs.com/qieqiemin/p/10246881.html
Copyright © 2011-2022 走看看