CF-805C
C. Find Amirtime limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
InputThe first line contains a single integer n (1 ≤ n ≤ 105) — the number of schools.
OutputPrint single integer: the minimum cost of tickets needed to visit all schools.
Examplesinput2output0input10output4NoteIn 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 ;
}
最新文章
- 使用mac 终端 用sublime 目标文件或目标文件夹
- Linux解压命令大全
- js滚动条滚动到某个元素位置
- (转)javascript 奇淫巧技44招
- IOS中的编码规范
- 关于sizeof 跟strlen 的区别
- dbutils中实现数据的增删改查的方法,反射常用的方法,绝对路径的写法(杂记)
- 10-利用com组件读取office
- c++中的const参数,const变量,const指针,const对象,以及const成员函数
- C++中rand()函数的用法
- 利用Pattern和Mather来禁止特殊字符的输入
- js数组、内置对象、自定义对象
- docker命令不需要敲sudo的方法
- bzoj:1941: [Sdoi2010]Hide and Seek
- git操作github仓库基本操作
- mssqlserver超级班助类 带详细用法
- Survey项目总结
- ionic1 添加百度地图插件 cordova-plugin-baidumaplocation
- 亲写javascript 各类面试题
- 开源项目Bug悬赏任务
热门文章
- Web开发者用什么编辑器?
- Codeforces 490F Treeland Tour 树上的最长上升子序列
- QC3.0快充技术详解
- Centos 安装Puppet
- C#.NET开源项目、机器学习、Power BI (转载)
- NTAG 标签
- wpf Style也继承(包含内部定义事件)
- xcode升级到6.0以后遇到的警告错误 原帖链接http://www.cocoachina.com/bbs/simple/?t112432.html
- iOS开发教程:Storyboard全解析-第一部分
- 【BZOJ1085】[SCOI2005]骑士精神 双向BFS