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


    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块方块。

    具体代码如下:

    1. #include
    2. #include
    3. #include
    4. #include
    5. #include
    6. #include
    7. using namespace std;
    8. signed main()
    9. {
    10. int T;
    11. cin >> T;
    12. while(T--){
    13. int n1, n2, n3, n4;
    14. scanf("%d%d%d%d", &n1, &n2, &n3, &n4);
    15. int mx = n2+n3+min(n4+n1, 2*n1+1);
    16. int mn = n1+n2+n3-min(n2, n3);
    17. if(mn == n1 && n4 != 0) mn++;
    18. printf("%d %d\n", mn, mx);
    19. }
    20. return 0;
    21. }

  • 相关阅读:
    Verilog仿真跨模块调用内部信号的方法
    Hadoop之小文件问题及解决方案
    预制菜还没火,加盟商已经亏惨了
    centos 安装freeswitch
    Carla学习笔记(二)服务器跑carla,本地运行carla-ros-bridge并用rviz显示
    如何在 SAP ABAP 系统中使用 Adobe Form
    037-JTree控件使用讲解
    Java程序员必学知识:高并发+微服务+数据结构+Mybatis实战实践
    3D人像手办定制业务再掀热潮,这一次有怎样的革新?(方法篇)
    Mybatis传统方式实现Dao层
  • 原文地址:https://blog.csdn.net/m0_55982600/article/details/126274121