Codeforces Round #411 (Div. 2)C. Find Amir(想法题)

传送门

Description

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.

Sample Input

2

10

Sample Output

0

4

Note

In the first example we can buy a ticket between the schools that costs .

思路

题解:因为从学校 i 到学校 j 花费为 ,因此尽量使1与n搭配,2与n - 1搭配,那么接下来要解决的就是联通这些搭配。从样例我们可以写出如下:

1      2     3     4    5

10    9     8     7    6

那么我们就可以从10到2,9到3,8到4...每次花费为1。按照这种策略可使最后结果最小。

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	scanf("%d",&n);
	if (n % 2 == 0)
	{
		printf("%d\n",n/2-1);
	}
	else	printf("%d\n",n/2);
	return 0;
}

  

时间: 2024-08-08 05:12:17

Codeforces Round #411 (Div. 2)C. Find Amir(想法题)的相关文章

【推导】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(){ scanf("%d",&n); printf("%d\n",(n-1)/2); return 0; }

Codeforces Round #345 (Div. 2)C. Watchmen(想法题)

传送门 Description Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi). They need to arrange a plan,

Codeforces Round #259 (Div. 2) (简单模拟实现题)

题目链接:http://codeforces.com/problemset/problem/454/A A. Little Pony and Crystal Mine time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Twilight Sparkle once got a crystal from the Crystal Mine

Codeforces Round #260 (Div. 2) A. Laptops(简单题)

题目链接:http://codeforces.com/problemset/problem/456/A A. Laptops time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day Dima and Alex had an argument about the price and quality of laptops.

Codeforces Round #423 (Div. 2) D. High Load(构造题)

题目链接:Codeforces Round #423 (Div. 2) D. High Load 题意: 给你一个数n和k,让你构造出一颗树,有k个叶子节点,使得这棵树的任意两个点的距离的最大值最小. 题解: 显然要使得这棵树的任意两个点的距离的最大值最小,每个点离树根越近越好. 然后要求有k个叶子节点,所以我就任意选一个点为根,然后构成一棵m叉的树就行了. 最大距离的最小值就是离根最远的和最近的加一加就行了. 1 #include<cstdio> 2 #define F(i,a,b) for

Codeforces Round 411 Div.2 题解

A Fake NP standard input/output 1 s, 256 MB Submit Add to favourites x3673 B 3-palindrome standard input/output 1 s, 256 MB Submit Add to favourites x3760 C Find Amir standard input/output 1 s, 256 MB Submit Add to favourites x3503 D Minimum number o

Codeforces Round #411 (Div. 2)

A题 分析:傻逼题,两个数的差不大于1输出任意一个,否则输出2 1 #include "iostream" 2 #include "cstdio" 3 #include "cstring" 4 #include "cmath" 5 using namespace std; 6 int main() 7 { 8 long long a,b; 9 while(cin>>a>>b) 10 { 11 if(ab

2017-5-5-Train:Codeforces Round #411 (Div. 2)

A. Fake NP(数论水题) Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divi

Codeforces Round #411 (Div. 2)D. Minimum number of steps(贪心)

传送门 Description We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a subs