Codeforces Round #411 C. Find Amir

来源:互联网 发布:编辑身份证照片软件 编辑:程序博客网 时间:2024/05/29 04:11

题意

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 (i+j) mod (n+1) 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.

任意选择起点和终点,要求遍历标号为 1 ~ n 的学校,从学校 i 到达学校 j 的花费为 (i+j)%(n+1) 。求遍历所有学校的最小费用。

解题思路

根据 (i+j) % (n+1) 可以得出:

1n 费用为 0

2n1 费用为 0

3n2 费用为 0

因此,遵循下列路径的走法将是最小费用 1n2n1... 。最小为 n12

代码

#include<bits/stdc++.h>using namespace std;int main(){    int n;    scanf("%d",&n);    printf("%d\n", (n-1)/2);}
0 0
原创粉丝点击