Codeforces Round #433 (Div. 2)
来源:互联网 发布:潘多拉淘宝 编辑:程序博客网 时间:2024/06/04 19:55
Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartments that are numbered from 1 to n and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale.
Maxim often visits his neighbors, so apartment is good for him if it is available for sale and there is at least one already inhabited apartment adjacent to it. Maxim knows that there are exactly k already inhabited apartments, but he doesn't know their indices yet.
Find out what could be the minimum possible and the maximum possible number of apartments that are good for Maxim.
The only line of the input contains two integers: n and k (1 ≤ n ≤ 109, 0 ≤ k ≤ n).
Print the minimum possible and the maximum possible number of apartments good for Maxim.
6 3
1 3
In the sample test, the number of good apartments could be minimum possible if, for example, apartments with indices 1, 2 and 3 were inhabited. In this case only apartment 4 is good. The maximum possible number could be, for example, if apartments with indices 1, 3and 5 were inhabited. In this case all other apartments: 2, 4 and 6 are good.
题意:
有n个房间排成一排,门牌号从 1 到 n ,已知有k个房间已经住了人,求最少和最多适合Maxim的房间的个数
思路:
一个有人住的房间可以产生两个适合Maxim的房间,所以最多适合Maxim的房间数为 min(k*2,n-k)个,最少为1(所有住人的房间都相连排在一边)或0(所有房间都住人了或都没住人)
#include<iostream>#include<string.h>#include<stdio.h>#include<math.h>#define LL long longusing namespace std;int main(){ LL n,k; scanf("%lld%lld",&n,&k); if(k==n||k==0) {printf("0 0");return 0;} printf("1 %lld",min(k*2,n-k)); return 0;}
- Codeforces Round #433 (Div. 2)
- Codeforces Round #433 (Div. 2)
- Codeforces Round #433 (Div. 2)
- Codeforces Round #433 (Div.2)
- Codeforces Round #433 (Div. 2)
- Codeforces Round#433 div 2
- Codeforces Round #433 (Div. 2)A. Fraction
- Codeforces Round #433 (Div. 2) C. Planning
- Codeforces Round #433 Div. 2 C
- Codeforces Round #433 (Div. 2) A. Fraction
- Codeforces Round #433 (Div. 2) C. Planning
- Codeforces Round #433 (Div. 2) 题解
- Codeforces Round #433 (Div. 2) E. Boredom
- Codeforces Round #433 (Div. 2) 题解
- Codeforces Round #433 (Div. 2) 总结
- Codeforces Round #433 Div. 2 A. Fraction
- Codeforces Round #433 (Div. 2)A&B
- Codeforces Round #102 (Div. 2)
- 关于javascript和servlet的ajax入门模版
- break,continue,return的区别
- 在一个重男轻女的国家里,每个家庭都想生男孩,如果他们生的孩子是女孩,就再生一个,直到生下的是男孩为止。这样的国家,男女比例会是多少?
- 插入排序-java
- 深入理解数据库中的乐观锁与悲观锁
- Codeforces Round #433 (Div. 2)
- 一分钟读懂互联网广告竞价策略
- 乐安全内嵌广告屏蔽原理
- python操作Excel读写--使用xlrd
- jq 删除指定id, 并无卵用,不如直接替换掉,禁止提交
- 大数据集群-这是一篇longlong的博客
- 系统吞吐量(TPS)、用户并发量、性能测试概念和公式
- node.js 关于timeout函数
- JAVA基础知识一