Find Amir
来源:互联网 发布:ubuntu dash to dock 编辑:程序博客网 时间:2024/05/29 10:28
题目链接 http://codeforces.com/problemset/problem/804/A
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.
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of schools.
Print single integer: the minimum cost of tickets needed to visit all schools.
2
0
10
4
第一行输入n,表示有标号从1~n的n所学校,一个人想要把这n所学校转一遍,但是没两所学校之间需要门票,票价为(i+j)mod(n+1),也就是学校序号和对(n+1)取余。题目要求输出转完n所学校话费最少的钱,并输出。
解题思路:
考察逻辑思维的题:局一组例子便明白:
如果n为偶数:
1 2 3 4 5
10 9 8 7 6
首先最大的与最小的之间买一张门票(1和10 2和9......),票价为0,。然后最大的和最小的之间买一张门票(10和2 9和3 8和4......),每张票价1,达到最小。
如果n为偶数的话,自己可以画画,其实差不多。
代码:
#include<iostream>using namespace std;int main(){ int n; while(cin>>n) { if(n%2==0) cout<<n/2-1<<endl; else cout<<n/2<<endl; } return 0;}
- Find Amir
- Codeforces805 C. Find Amir
- CF411div2C.Find Amir
- C. Find Amir
- [Codeforces805] C. Find Amir
- A. Find Amir
- CodeForces 805C Find Amir
- CodeFroces 804A Find Amir
- Codeforces 805C Find Amir
- codeforces 804A Find Amir
- codeforces 411 div2-find amir
- Codeforces Round #411 C. Find Amir
- CF#804 A. Find Amir(贪心)
- codeforces 804A——Find Amir
- 【Codeforces Round #411 (Div. 1)】Codeforces 804A Find Amir
- Codeforces Round #411 (Div. 2) C. Find Amir
- Codeforces Round #411(Div. 2)C. Find Amir【思维】
- Codeforces Round #411 C.Find Amir (思维题)
- java编码108条规则总结
- Struts2通配符CRUD和注解CRUD
- Linux之vim、压缩与解压缩
- 深度搜索
- 正确解决androidstudio弹出"waiting for debugger"
- Find Amir
- hex文件格式
- js中常见的this.index面试基础知识问题
- 中国剩余定理-数硬币
- HDU-6046 hash(哈希)
- 关于dedecms数据量大以后生成目录缓慢的问题解决
- poj3250 Bad Hair Day (单调栈)
- [机器学习]回归分析案例 --- 网游排名分析
- TCP-IP学习笔记(七)——ARP:地址解析协议