C. Find Amir
time limit per test  

1 second

memory limit per test  

256 megabytes

 

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.

 
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)元,Sajjad想知道他参观完所有学校所需要的最少花费
解题思路:
       本来想建个图用最小生成树写勒,但是发现可以利用(i+j)%(n+1)造出几条花费为0,并且两条花费为0的道路、

      连接的最小花费为1,所以只用判断一共可以造出几条花费为0的路即可。

     拿第二组样例来说,(1,10),(2,9),(3,8),(4,7),(5,6)这5条路的花费为0,用(10,2)来连接(1,10)和(2,9)这两条路花费为1...

     所以最后的花费为4.

     当n为奇数时情况有些不同(试着推一推)把奇数+1处理即可。

 #include <stdio.h>
int main ()
{
int n;
while(~scanf("%d",&n))
{
printf("%d\n",(n+)/-);
}
return ;
}

Codeforces Round #411 (Div. 2) C. Find Amir的更多相关文章

  1. 【推导】Codeforces Round #411 (Div. 1) A. Find Amir

    1 2 3 4 5 6 7 4-5-3-6-2-7-1 答案是(n-1)/2 #include<cstdio> using namespace std; int n; int main() ...

  2. Codeforces Round #411 (Div. 2)(A,B,C,D 四水题)

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

  3. Codeforces Round #411 (Div. 2)

    来自FallDream的博客,未经允许,请勿转载,谢谢. 由于人傻又菜 所以这次又滚去div2了  一堆结论题真的可怕 看见E题不是很有思路   然后就去大力搞F题  T了最后一个点 真的绝望   但 ...

  4. Codeforces Round #411 (Div. 2) 【ABCDE】

    A. Fake NP 题意:给你l,r,让你输出[l,r]里面除1以外的,出现因子数量最多的那个数. 题解:如果l==r输出l,否则都输出2 #include<bits/stdc++.h> ...

  5. Codeforces Round #411 (Div. 2) A-F

    比赛时候切了A-E,fst了A Standings第一页只有三个人挂了A题,而我就是其中之一,真™开心啊蛤蛤蛤 A. Fake NP time limit per test 1 second memo ...

  6. Codeforces Round 411 Div.2 题解

    A Fake NP standard input/output s, MB Submit Add to favourites x3673 B -palindrome standard input/ou ...

  7. Codeforces Round #411 (Div. 1) D. Expected diameter of a tree

    题目大意:给出一个森林,每次询问给出u,v,问从u所在连通块中随机选出一个点与v所在连通块中随机选出一个点相连,连出的树的直径期望(不是树输出-1).(n,q<=10^5) 解法:预处理出各连通 ...

  8. Codeforces Round #411 div 2 D. Minimum number of steps

    D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input st ...

  9. 【DFS】【贪心】Codeforces Round #411 (Div. 1) C. Ice cream coloring

    对那个树进行dfs,在动态维护那个当前的冰激凌集合的时候,显然某种冰激凌仅会进出集合各一次(因为在树上形成连通块). 于是显然可以对当前的冰激凌集合贪心染色.暴力去维护即可.具体实现看代码.map不必 ...

随机推荐

  1. TCP/IP——何时用UDP代替TCP

    UDP和TCP UDP和TCP都有其自身的特点,不同的应用场景和要求需要使用不同的协议来传输,那么何时我们可以用UDP代替TCP呢. UDP 的优点 UDP支持广播和多播,事实上如果应用程序使用广播或 ...

  2. 【http协议】浅谈

    [http协议]浅谈 一. 概述 http,超文本传输协议(HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议. 请求与响应: 客户端发送请求,服务器端响应数 ...

  3. springboot项目,执行查询方法报错

    org.hibernate.LazyInitializationException: could not initialize proxy [com.myproject.sell.dataobject ...

  4. [转] Gitlab 8.x runner安装与配置

    [From]http://muchstudy.com/2018/07/13/Gitlab-8-x-runner%E5%AE%89%E8%A3%85%E4%B8%8E%E9%85%8D%E7%BD%AE ...

  5. Html checkbox全选

    html中全选 <table class="data-table td-center"> <tr> <td><input type=&qu ...

  6. git提交过程中遇到的 index.lock 问题导致无法提交的解决方法

    在提交代码的过程中,可能会遇到下面的问题: fatal: Unable to create 'C:/programLists/zzw-q1/.git/index.lock': File exists. ...

  7. C# 实现IP视频监控(摄像头)画面推送(简单的不能再简单的DEMO)

    最近继续在家休息,在完成上一个Python抓取某音乐网站爬虫后,琢磨着实现一个基于HTTP推送的 IP视频监控,比如外出的时候,在家里 开启一个监控端(摄像头+服务端),可以看到实时画面,如果再加上自 ...

  8. Jquery中和ajax有关的方法

    Jquery关于ajax有一系列的方法函数,单单知道$.ajax()显然是不够的,接下来我们对该系列的方法函数逐一研究下. ajaxComplete(callback).ajaxError(callb ...

  9. android studio应用修改到android源码中作为内置应用

    1. 方法一:导入,编译(太麻烦,各种不兼容问题) android studio和eclipse的应用结构目录是不同的,但是在android源码中的应用基本上都是使用的eclipse目录结构(在/pa ...

  10. centos6.x硬件信息统计脚本

    #!/bin/bash Line='===========' #linux发行版名称 if [[ -f /usr/bin/lsb_release ]]; then OS=$(/usr/bin/lsb_ ...