C. 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
Note

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

题意:

共有n间学校,往返i,j两学校之间的票的价格为(i+j)%(n+1)。

求最小遍历所有学校的花费。

当n为偶数时,最小花费为n/2-1

1~n为0,n~2为1,2~n-1为0,以此类推。

当n为奇数时,需要连接中间的值,故再加一,为n/2.

附AC代码:

 #include<bits/stdc++.h>
using namespace std; int main(){
int n,ans=;
cin>>n;
if(n%){
ans=n/;
}
else{
ans=n/-;
}
cout<<ans<<endl;
return ;
}

最新文章

  1. 使用mac 终端 用sublime 目标文件或目标文件夹
  2. Linux解压命令大全
  3. js滚动条滚动到某个元素位置
  4. (转)javascript 奇淫巧技44招
  5. IOS中的编码规范
  6. 关于sizeof 跟strlen 的区别
  7. dbutils中实现数据的增删改查的方法,反射常用的方法,绝对路径的写法(杂记)
  8. 10-利用com组件读取office
  9. c++中的const参数,const变量,const指针,const对象,以及const成员函数
  10. C++中rand()函数的用法
  11. 利用Pattern和Mather来禁止特殊字符的输入
  12. js数组、内置对象、自定义对象
  13. docker命令不需要敲sudo的方法
  14. bzoj:1941: [Sdoi2010]Hide and Seek
  15. git操作github仓库基本操作
  16. mssqlserver超级班助类 带详细用法
  17. Survey项目总结
  18. ionic1 添加百度地图插件 cordova-plugin-baidumaplocation
  19. 亲写javascript 各类面试题
  20. 开源项目Bug悬赏任务

热门文章

  1. Web开发者用什么编辑器?
  2. Codeforces 490F Treeland Tour 树上的最长上升子序列
  3. QC3.0快充技术详解
  4. Centos 安装Puppet
  5. C#.NET开源项目、机器学习、Power BI (转载)
  6. NTAG 标签
  7. wpf Style也继承(包含内部定义事件)
  8. xcode升级到6.0以后遇到的警告错误 原帖链接http://www.cocoachina.com/bbs/simple/?t112432.html
  9. iOS开发教程:Storyboard全解析-第一部分
  10. 【BZOJ1085】[SCOI2005]骑士精神 双向BFS