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要求遍历1~n,遍历是可以任意移动,从i移动到j花费(i+j)%

(n+1),问最小花费

思路,贪心尽可能凑n+1,我们可以很清楚发现1和n凑2和n-1凑,这样走都不用花费

,而他们之间转化两两之间最小花费1,n走到2,n-1走3,所以偶数个需走n/2-1,奇数

走n/2,合并起来就是(n-1)/2

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define inf 0x3f3f3f3f
#define LL long long int main()
{
int n;
scanf("%d",&n);
printf("%d\n",(n-1)/2);
return 0;
}

Codeforces805 C. Find Amir 2017-05-05 08:41 140人阅读 评论(0) 收藏的更多相关文章

  1. Codeforces805 A. Fake NP 2017-05-05 08:30 327人阅读 评论(0) 收藏

    A. Fake NP time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  2. c#委托和事件(下) 分类: C# 2015-03-09 08:42 211人阅读 评论(0) 收藏

    C#中的委托和事件(下) 引言 如果你看过了 C#中的委托和事件 一文,我想你对委托和事件已经有了一个基本的认识.但那些远不是委托和事件的全部内容,还有很多的地方没有涉及.本文将讨论委托和事件一些更为 ...

  3. .net 实现Office文件预览 Word PPT Excel 2015-01-23 08:47 63人阅读 评论(0) 收藏

    先打个广告: .Net交流群:252713569 本人QQ :524808775 欢迎技术探讨, 近期公司要求上传的PPT和Word都需要可以在线预览.. 小弟我是从来没有接触过这一块的东西 感觉很棘 ...

  4. walk around by The provided App differs from another App with the same version and product ID 分类: Sharepoint 2015-07-05 08:14 4人阅读 评论(0) 收藏

    'm currently developing a SharePoint 2013 application. After a few deployments via Visual Studio, I ...

  5. hdu 1047 (big integer sum, fgets or scanf, make you func return useful infos) 分类: hdoj 2015-06-18 08:21 39人阅读 评论(0) 收藏

    errors made, boundary conditions, <= vs < , decreasing vs increasing , ++, –, '0'/'1' vs 0/1 p ...

  6. A simple problem 分类: 哈希 HDU 2015-08-06 08:06 1人阅读 评论(0) 收藏

    A simple problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...

  7. 周赛-Integration of Polynomial 分类: 比赛 2015-08-02 08:40 10人阅读 评论(0) 收藏

    Integration of Polynomial Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/O ...

  8. 周赛-Heros and Swords 分类: 比赛 2015-08-02 08:30 11人阅读 评论(0) 收藏

    Heros and Swords Time Limit: 6000/3000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Su ...

  9. 周赛-KIDx's Pagination 分类: 比赛 2015-08-02 08:23 7人阅读 评论(0) 收藏

    KIDx's Pagination Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) S ...

随机推荐

  1. jQuery:总体掌握

    链式编程....方法多,属性无法得到对象进行链式.vs10自动完成.书籍锋利的jQuery vsdoc有智能提示开发时候用,开发完之后,换成min压缩版的. 经验:打开网站文件夹.可以把vs网站上的解 ...

  2. Dotfuscator Professional Edition获取代码发布和混淆代码

    1 Dotfuscator Professional Edition 4.9 破解版 下载地址:http://www.pc0359.cn/downinfo/39815.html 备份地址:C:\D\9 ...

  3. Linux初学时的一些常用命令(2)

    文件的操作   创建一个文件    touch 文件名  创建一个空白的文件 复制文件    cp 文件 目录/文件名     例如:      cp 1.txt 2.txt      cp 1.tx ...

  4. Syncthing搭建

    现在貌似只有windows和linux比较号装. 安装 先从官网下载好Windows 32位版(我本本对应的系统版本)的Syncthing,解压后可以看到如下文件结构   Syncthing文件结构 ...

  5. Python3 exec 函数

    Python3 exec 函数  Python3 内置函数 描述 exec 执行储存在字符串或文件中的 Python 语句,相比于 eval,exec可以执行更复杂的 Python 代码. 语法 以下 ...

  6. java实现24点游戏代码

    import java.util.Arrays;import java.util.Scanner; public class Test07 {    public static void main(S ...

  7. SVN客户端的安装和使用

    ----------------------siwuxie095 SVN 客户端的安装 1.SVN 客户端,选择 TortoiseSVN,下载链接: https://tortoisesvn.net/d ...

  8. PAT L1-020 帅到没朋友(模拟数组)

    当芸芸众生忙着在朋友圈中发照片的时候,总有一些人因为太帅而没有朋友.本题就要求你找出那些帅到没有朋友的人. 输入格式: 输入第一行给出一个正整数N(≤100),是已知朋友圈的个数:随后N行,每行首先给 ...

  9. django的视图函数介绍

    我们来看下views视图中的函数的request这个变量到底有哪些方法和属性 1.request.path 结果:不包括域名和端口的url路径 2.request.method 结果:这次请求的方法, ...

  10. 12-matlab简单读excel

    数据读入: clc; clear; AllNeedDate = xlsread('E:\a-建模\2018-5月校赛\2018年数学建模校内挑战赛题目\挑战赛A题\附件2:各城镇月度需求数据.xlsx ...