1004题
1.题目大意:给出n个方块,每个方块的左右都可能是黑或白。将这些方块排成一列,如果两个相邻方块相连接的面都是黑色,那么这两个方块会连在一起。求连通块的最大最小数量。
2.分析:对于最少的情况,先将所有B拼一起,再把一个L和R分为一组拼起来。如果至少一组LR并且至少一块B的话,可以把一组LR拆开拼在B的两边,又可减少一个
对于最多的情况,把所有的L放到最左边,R放到最右边,之后尽可能用E把B隔开。
3.代码:
using namespace std;
int main() {
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
int e, l, r, b;
scanf("%d %d %d %d", &e, &l, &r, &b);
int tempe = e, templ = l, tempr = r, tempb = b, temp;
if (tempb > 0) {
if (templ > 0)templ--;
if (tempr > 0)tempr--;
temp = min(templ, tempr);
cout << tempe + templ + tempr - temp + 1 << " ";
}
else {
temp = min(templ, tempr);
cout << tempe + templ + tempr - temp << " ";
}
templ = l, tempr = r;
if (tempb - 1 > tempe)cout << templ + tempr + 1 + tempe * 2 << endl;
else cout << templ + tempr + tempe + tempb<<endl;
}
}