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. 微信小程序 没有找到node_modules目录 ,小程序引入vant框架报错。

    如果大家是按照官网的引入方法,是否报错如图 不着急,大家就试试我的方法吧!两步走完美搞定! 第一步: 在小程序顶部点击设置->项目设置,会弹出下面的窗口.大家把使用npm模块勾上对勾. 第二步: ...

  2. 02. css3有哪些新特性?

    2.css3有哪些新特性? 1. CSS3实现圆角(border-radius),阴影(box-shadow), 2. 对文字加特效(text-shadow.),线性渐变(gradient),旋转(t ...

  3. mongodb与python随手记

    在python中使用pymongo连接mongodb数据库. 基本代码如下: from pymongo import MongoClient client = MongoClient('127.0.0 ...

  4. (转)Go语言核心36讲之Go语言学习路线

  5. 微信小程序回到顶部的两种方式

    一,使用view形式的回到顶部 <image src='../../img/button-top.png' class='goTop' hidden='{{!floorstatus}}' bin ...

  6. vue开发的一些设置以及技巧

    引入其它css样式   需要加~   @找到的是src目录 对于常用的路径可以设置别名     @代表src                  常用的地址在webpack.base.conf.js中 ...

  7. 1、The Fctory Pattern(工厂模式:解决对象创建问题)

    The Fctory Pattern  处理对象创建,客户端可以申请一个对象而不用知道对象被那个class创建.可以方便地解耦对象的使用和创建,有两种实现,工厂方法和抽象工厂. Method(工厂方法 ...

  8. range() 和 np.arange()区别

    range() 和 np.arange()区别 range(start,stop,step) 三个参数都必须是整数 np.arange()没有此类约束

  9. fish shell version

    如果你使用 fish shell, 想要自己定义变量,或者函数,或者alias, 不要使用      version     这个名字, 因为,version 这个名字 被 fish 本身占了.... ...

  10. fastclick源码分析

    https://www.cnblogs.com/diver-blogs/p/5657323.html  地址 fastclick.js源码解读分析 阅读优秀的js插件和库源码,可以加深我们对web开发 ...