Codeforces805 C. Find Amir 2017-05-05 08:41 140人阅读 评论(0) 收藏
1 second
256 megabytes
standard input
standard output
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
In the first example we can buy a ticket between the schools that costs .
——————————————————————————————————————
题目的意思是给出n要求遍历1~n,遍历是可以任意移动,从i移动到j花费(i+j)%
(n+1),问最小花费
思路,贪心尽可能凑n+1,我们可以很清楚发现1和n凑2和n-1凑,这样走都不用花费
,而他们之间转化两两之间最小花费1,n走到2,n-1走3,所以偶数个需走n/2-1,奇数
走n/2,合并起来就是(n-1)/2
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define inf 0x3f3f3f3f
#define LL long long int main()
{
int n;
scanf("%d",&n);
printf("%d\n",(n-1)/2);
return 0;
}
Codeforces805 C. Find Amir 2017-05-05 08:41 140人阅读 评论(0) 收藏的更多相关文章
- Codeforces805 A. Fake NP 2017-05-05 08:30 327人阅读 评论(0) 收藏
A. Fake NP time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- c#委托和事件(下) 分类: C# 2015-03-09 08:42 211人阅读 评论(0) 收藏
C#中的委托和事件(下) 引言 如果你看过了 C#中的委托和事件 一文,我想你对委托和事件已经有了一个基本的认识.但那些远不是委托和事件的全部内容,还有很多的地方没有涉及.本文将讨论委托和事件一些更为 ...
- .net 实现Office文件预览 Word PPT Excel 2015-01-23 08:47 63人阅读 评论(0) 收藏
先打个广告: .Net交流群:252713569 本人QQ :524808775 欢迎技术探讨, 近期公司要求上传的PPT和Word都需要可以在线预览.. 小弟我是从来没有接触过这一块的东西 感觉很棘 ...
- walk around by The provided App differs from another App with the same version and product ID 分类: Sharepoint 2015-07-05 08:14 4人阅读 评论(0) 收藏
'm currently developing a SharePoint 2013 application. After a few deployments via Visual Studio, I ...
- hdu 1047 (big integer sum, fgets or scanf, make you func return useful infos) 分类: hdoj 2015-06-18 08:21 39人阅读 评论(0) 收藏
errors made, boundary conditions, <= vs < , decreasing vs increasing , ++, –, '0'/'1' vs 0/1 p ...
- A simple problem 分类: 哈希 HDU 2015-08-06 08:06 1人阅读 评论(0) 收藏
A simple problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- 周赛-Integration of Polynomial 分类: 比赛 2015-08-02 08:40 10人阅读 评论(0) 收藏
Integration of Polynomial Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/O ...
- 周赛-Heros and Swords 分类: 比赛 2015-08-02 08:30 11人阅读 评论(0) 收藏
Heros and Swords Time Limit: 6000/3000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Su ...
- 周赛-KIDx's Pagination 分类: 比赛 2015-08-02 08:23 7人阅读 评论(0) 收藏
KIDx's Pagination Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) S ...
随机推荐
- Ubuntu下面网络固定ip
https://jingyan.baidu.com/article/e5c39bf5bbe0e739d7603396.html
- Hadoop 初始化系统
hadoop namenode -format 或者 hdfs namenode -format 2.执行hadoop sbin 目录下的 start-dfs.sh start-yarn.sh3.查看 ...
- 基于Woodstox的StAX 2 (Streaming API for XML)解析XML
StAX (Streaming API for XML)面向流的拉式解析XML,速度快.占用资源少,非常合适处理大数据量的xml文件. 详细教程和说明可以参见以下几篇文章: 使用 StAX 解析 XM ...
- nat 类型及打洞原理
nat 类型分4种 1.全锥形 full cone A 与 主机B交互,nat转换 A的内部地址及端口为 ip1 port1,ip1和port1为对外地址,任何机器能访问. 2.ip 受限制(对B而 ...
- 3.Longest Substring Without Repeating Characters(string; HashTable)
Given a string, find the length of the longest substring without repeating characters. For example, ...
- War(最短路+最大流)
War http://acm.hdu.edu.cn/showproblem.php?pid=3599 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- jquery 动态添加的代码不能触发绑定事件
今天发现jQuery对动态添加的元素不触发事件,比如blur.click事件等 参考文章证明了我的结论,并给出了原因及解决方案 原因:程序找不到动态添加的节点. 解决方案:在绑定父元素后的子元素 $( ...
- 罗马数字转整数 · Roman to Integer
13. Roman to Integer [抄题]: [暴力解法]: 时间分析: 空间分析: [思维问题]: 没有想到罗马字是逆序的情况 没有想到要先用toCharArray()方法把字符串拆成一个字 ...
- 【笔记】C#往TextBox的方法AppendText加入的内容里插入换行符
C# TextBox换行[huan hang]时你往往会想到直接付给一个含有换行[huan hang]符"\n"的字符[zi fu]串[zi fu chuan]给Text属性[sh ...
- sqlserver数据库维护常用sql
1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 drop database dbname 3.说明:备份sql server --- 创建 备份 ...