[贪心]Black Magic 2022杭电多校第7场 1004

22 篇文章 0 订阅

Problem Description

HoshiYo is learning Black Magic with nn blocks. The left and right sides of each block are painted black or white. HoshiYo arranges the blocks in a row in a certain order without rotating them and then releases the Black Magic. Here's what happens next:

  • For any two adjacent blocks, if the right side of the left block and the left side of the right block are both painted black, then the two sides will be pasted together making the two blocks into one.

HoshiYo wants to know the minimum and maximum blocks he can get after releasing the Black Magic.

Input

The first line contains an integer TT (1 \le T \le 4\times 10^31≤T≤4×103), indicating the number of test cases.

Each test case contains four integers E,L,R,BE,L,R,B (0 \le E,L,R,B \le 10^5, E+L+R+B\ge 10≤E,L,R,B≤105,E+L+R+B≥1), indicating the number of blocks.

  • EE: the number of blocks whose both sides are painted white.
  • LL: the number of blocks whose left side is painted black and right side is painted white.
  • RR: the number of blocks whose right side is painted black and left side is painted white.
  • BB: the number of blocks whose both sides are painted black.

It guaranteed that the sum of E+L+R+BE+L+R+B over all test cases won't exceed 10^6106.

Output

For each test case, output two integers in a single line, indicating the minimum and maximum blocks HoshiYo can get.

Sample Input

3

1 1 1 1

1 2 3 4

3 4 5 6

Sample Output

2 4

4 8

8 16

Hint

Let's denote a block by (x,y)(x,y), where xx indicates the color on the left side, and yy indicates the color on the right side. We use 00 to represent white and 11 to represent black.

For the first test case in the sample, here is a possible solution to get the minimum number of blocks:

(0,0) \quad (0,1) \quad (1,1) \quad (1,0)(0,0)(0,1)(1,1)(1,0)

As shown above, the last three blocks will be pasted into one.

And here is a possible solution to get the maximum number of blocks:

(0,0) \quad (1,0) \quad (1,1) \quad (0,1)(0,0)(1,0)(1,1)(0,1)

As shown above, any two blocks will not be pasted together.

题意: 有4种方块,分别是两侧全白,左侧白右侧黑,左侧黑右侧白,两侧全黑,分别给出这四种方块的数量,要求将这些方块拍成一排,如果相邻两接触面均黑那可以合并成一个方块,分别输出最少方块数和最多方块数。

分析: 对于最多的方块,可以将左黑右白放在最左侧,将左白右黑放在最右侧,然后中间用全黑和全白交叉放,最后需要n2+n3+min(n4+n1, 2*n1+1)个方块。对于最少的方块,可以显然左黑右白和左白右黑两两合并,让全黑直接夹在其中,只要存在一对左黑右白和左白右黑,那么全黑的方块就是没有贡献的,所以需要n1+n2+n3-min(n2, n3)块方块,如果n2和n3均为0且n4不为0那么最后还需要+1块方块。

具体代码如下:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
using namespace std;

signed main()
{
	int T;
	cin >> T;
	while(T--){
		int n1, n2, n3, n4;
		scanf("%d%d%d%d", &n1, &n2, &n3, &n4);
		int mx = n2+n3+min(n4+n1, 2*n1+1);
		int mn = n1+n2+n3-min(n2, n3);
		if(mn == n1 && n4 != 0) mn++;
		printf("%d %d\n", mn, mx);
	} 
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值