1004-Black Magic
题目大意:
给出一些方块,这些方块左右两面涂有白色或黑色,将这些方块相邻排列,相邻方块的两面都为黑色则合并,可以有不同排列方式,问最大和最小方块数
思路:
计算合并后方块的最大数量时,要尽可能少合并,计算最小数量时,要尽可能多合并
#include<iostream>
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;
}
}