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), '\0', 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=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/ int main()
{
ll n;
cin>>n;
ll ans=(n+)/-;
cout<<ans<<endl;
return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}

Find Amir CodeForces - 805C (贪心+思维)的更多相关文章

  1. Find Amir CodeForces 805C

    http://codeforces.com/contest/805/problem/C 题意:有n个学校,学校的编号是从1到n,从学校i到学校j的花费是(i+j)%(n+1),让你求遍历完所有学校的最 ...

  2. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

  3. 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas

    题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...

  4. Mike and distribution CodeForces - 798D (贪心+思维)

    题目链接 TAG: 这是我近期做过最棒的一道贪心思维题,不容易想到,想到就出乎意料. 题意:给定两个含有N个正整数的数组a和b,让你输出一个数字k ,要求k不大于n/2+1,并且输出k个整数,范围为1 ...

  5. 贪心/思维题 UVA 11292 The Dragon of Loowater

    题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <c ...

  6. T - Posterized(贪心思维)

    Description Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked hi ...

  7. codeforces 233 C. Cycles(贪心+思维)

    题目链接:http://codeforces.com/contest/233/problem/C 题意:在一个无相图中有N个长度为3 的回路,输出符合条件的图.注意此图的节点数不得超过100 题解:贪 ...

  8. codeforces 798 D. Mike and distribution(贪心+思维)

    题目链接:http://codeforces.com/contest/798/problem/D 题意:给出两串长度为n的数组a,b,然后要求长度小于等于n/2+1的p数组是的以p为下表a1-ap的和 ...

  9. codeforces 798 C. Mike and gcd problem(贪心+思维+数论)

    题目链接:http://codeforces.com/contest/798/problem/C 题意:给出一串数字,问如果这串数字的gcd大于1,如果不是那么有这样的操作,删除ai, ai + 1 ...

随机推荐

  1. 无根树的计数——prufer序列

    参考博客https://www.cnblogs.com/dirge/p/5503289.html (1)prufer数列是一种无根树的编码表示,类似于hash. 一棵n个节点带编号的无根树,对应唯一串 ...

  2. Matplotlib常用绘图示例

    一.Matplotlib介绍 Matplotlib是一个Python的2D绘图库,它以各种硬拷贝格式和跨平台的交互式环境生成出版质量级别的图形.通过Matplotlib,开发者可以仅需要几行代码,便可 ...

  3. Java SE和Java EE应用的性能调优

    凡事预则立,不预则废,和很多事情一样.Java性能调优的成功.离不开行动计划.方法或策略以及特定的领域背景知识.为了在Java性能调优工作中有所成就.你得超越"花似雾中看"的状态, ...

  4. centos7下安装docker(7docker base command 命令词典)

    上一章中我总结了学习docker 镜像时所用过的命令,今天先来将docker base command 记录一下,参考:https://docs.docker.com/edge/engine/refe ...

  5. Java中关于LockSupport的简单入门记录

    LockSupport的JDK的文档描述:Basic thread blocking primitives for creating locks and other synchronization c ...

  6. ORB-SLAM2(3) ROS下实时跑ORB_SLAM2

    Step1 : 运行内核 roscore Step2 : 启动相机 cd catkin_ws/src/usb_cam/launch #进入usb_cam驱动的安装目录 roslaunch my_cam ...

  7. leetcode 104. Maximum Depth of Binary Tree 111. Minimum Depth of Binary Tree

    104: class Solution { public: int maxDepth(TreeNode* root) { if(root == NULL) ; int left = maxDepth( ...

  8. CVE-2018-14634 - Linux create_elf_tables()中的整型溢出 - 翻译

    原文:https://seclists.org/oss-sec/2018/q3/274 摘要 Qualys研究实验室的安全团队发现一个位于Linux内核函数create_elf_tables()中的整 ...

  9. 动态分析Android程序

    快速定位程序关键点 代码注入法 插入log函数,输出调试信息. const-string v0,"TAG" const-string v1,"info" inv ...

  10. python之字符串、列表和元组

    先简单的了解一下两个相关概念 模块 python中的模块需要使用特殊的命令import来导入.格式:模块.函数.如下: 在确定自己不会导入多个同名函数的情况下,可以使用import命令的另外一种形式: ...