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. Java的定时调度

    一般在web开发中定时调度比较有用,因为要维护一个容器不关闭才可以一直定时操作下去. 定时调度:每当一段时间之后,程序就会自动执行,就称为定时调度.如果要使用定时调动,则必须要保证程序要始终运行着,也 ...

  2. nginx windows 安装为服务.

    安装Nginx 下载windows版nginx (http://nginx.org/download/nginx-1.10.0.zip),之后解压到需要放置的位置(D:\xampp\nginx) 将N ...

  3. POJ_2886 Who Gets the Most Candies? 【二分+树状数组】

    一.题目 POJ2886 二.分析 这个题目吧,开始没读懂,做的时候也没懂,WA的时候懂了.假设是第p个出圈的人有一个对应的因子个数$F(p)$,那么,题目求的就是这个$F(p)$最大的对应的人. 1 ...

  4. SqlServer数据库《基本》

    数据库简单说就是行.列组成的二维表 把列称为字段.每一行数据成为记录,能标识每一行的唯一字段称为主键 查询数据表时,索引可以提高查询速度,但是索引同时会降低新增和更新数据时的速度,应为还要更新索引. ...

  5. J: Just for fun

    J: Just for fun 时间限制: 1 s      内存限制: 128 MB        题目描述 最近carryon在准备考研复习高数,复习到微分学的时候看到一个求曲面某点的切平面的问题 ...

  6. CSS定位属性

                  定位属性                                                              position属性 1.      s ...

  7. 使用 json_serializable (flutter packages pub run build_runner build) 问题

    命令: flutter packages pub run build_runner build 使用 build_runner 生成 .g.dart 文件 flutter packages pub r ...

  8. Salesforce LINKS

    Salesforce的二次开发平台的多租户架构 http://blog.talkingdata.net/?p=4807 Salesforce 简介 https://www.cnblogs.com/ch ...

  9. MqttNet 通讯

    MQTT,IBM发明的物联网通讯协议基于tcp ip , 收集传感器上的数据. 下图理解:  broker 这里有很多消息,根据主题不同来进行区分,它这里可以保管所有连过来的客户端的数据,然后客户端, ...

  10. LCA(最近公共祖先)

    学习链接:https://baike.baidu.com/item/%E4%BC%B8%E5%B1%95%E6%A0%91/7003945?fr=aladdin 求LCA的方法有很多,在这里就只介绍一 ...