Codeforces 854 B Maxim Buys an Apartment

来源:互联网 发布:中日韩围棋 知乎 编辑:程序博客网 时间:2024/05/16 17:27

题目地址
题意:告诉你一个小区,里面有n间房子,只有有邻居的房子才能是好房子,现在告诉你有m间房子卖出去了,但是不知道房子的位置。让你求出好房子的最大数量和最小数量。
思路:最好的情况只有当n - m > m * 2时他才可能会有房子不是好房子(看下图),如果小于的话那剩下的房子都是好房子。最坏的情况就是全部靠边站,那就是1了。有两种情况需要特判,应该是房子全部卖出去了(n==m)或者没有房子卖出去(m==0),这时候就是输出0 0。
这里写图片描述

#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <set>#include <stack>#include <cmath>#include <cstdio>#include <algorithm>#include <iomanip>#define N 1110#define M 555005  #define LL __int64#define inf 0x3f3f3f3f#define lson l,mid,ans<<1#define rson mid+1,r,ans<<1|1#define getMid (l+r)>>1#define movel ans<<1#define mover ans<<1|1using namespace std;const LL mod = 1000000007;int main() {    cin.sync_with_stdio(false);    int a, b;    while (cin >> a >> b) {        if (a == b || b == 0) {            cout << "0 0" << endl;        }        else {            cout << "1 ";            if (a - b > b * 2) {                cout << b * 2 << endl;            }            else {                cout << a - b << endl;            }        }    }    return 0;}
原创粉丝点击