zoukankan      html  css  js  c++  java
  • Edu Cf Round 105 (Div. 2) B. Berland Crossword 1.读懂题, 2. 思维

    一. 原题链接 https://codeforces.com/contest/1494/problem/B

     

    二. 题意 + 题解:

    没看懂题目, 懵了好久,

    先狡辩一下当时误解的句子, 英语是硬伤了, 呜呜

    exactly U cells in the top row are black; //意为 : 最上行恰好有U个黑块

    Note that you can color zero cells black and leave every cell white. // 意为 : 你可以一个方格也不涂黑色, 并且可以都涂白色

    所以 U,R,D,L分别代表 最上行, 最右列, 最下行, 最左列的要求的黑块数目, 我们要做的就是该咋涂色, 使这2行2列满足.

    需要注意的是: 四个角里的颜色连着一行一列, 需分开讨论: 

    枚举每个角的黑色格子数(0或1),

    如果这一行(或列) 两角中黑格数目 <= 目标 && 可以涂黑色的数目 >= 目标,

    上下左右四趟都满足则输出YES, 那如何满足呢?

    1. 这一行(或列) 两角中黑格数目 <= 目标 :  若为行 则需 最左格+最右格黑格数目 <= 目标;

                      若为列  则需最上格加最下格黑格数目 <= 目标

    2.  可以涂黑色的数目 >= 目标 :  该行(或列)的格子数 - 2 + 两角中黑格数目;

                 其中该行(或列)的格子数n - 2 意为这一行(或列)不受其它列(或行)的干扰的格子数目

     只需将不符合条件的都踢出去就好了, 来个continue

    三. AC代码

    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        int t, n, u, r, l, d;
        cin >> t;
        while(t --)
        {
            bool ok = 0;
            cin >> n >> u >> r >> d >> l;
    //核心代码, 看着麻烦, 其实都是类似的代码
    for(int ul = 0; ul < 2; ul ++)//ul, ur, dl, dr分别为四个角的黑块数 for(int ur = 0; ur < 2; ur ++) for(int dr = 0; dr < 2;dr ++) for(int dl = 0; dl < 2; dl ++) { if(dr + ur > r || n - 2 + dr + ur < r)//如果这一行两角中黑格数目 <= 目标 && 可以涂黑色的数目 >= 目标 continue; if(ul + dl > l || n - 2 + ul + dl < l) continue; if(ul + ur > u || n - 2 + ul + ur < u) continue; if(dl + dr > d || n - 2 + dl + dr < d) continue; ok = true; break; } puts(ok? "YES" : "NO"); } return 0; }

     

    四.

    附原题:

    B. Berland Crossword
     

    Berland crossword is a puzzle that is solved on a square grid with nn rows and nn columns. Initially all the cells are white.

    To solve the puzzle one has to color some cells on the border of the grid black in such a way that:

    • exactly U cells in the top row are black;
    • exactly R cells in the rightmost column are black;
    • exactly D cells in the bottom row are black;
    • exactly L cells in the leftmost column are black.

    Note that you can color zero cells black and leave every cell white.

    Your task is to check if there exists a solution to the given puzzle.

    Input

    The first line contains a single integer tt (1t100; 1≤t≤1000) — the number of testcases.

    Then the descriptions of tt testcases follow.

    The only line of each testcase contains 55 integers n,U,R,D,L (2n100; 2≤n≤100; 0U,R,D,Ln).

    Output

    For each testcase print "YES" if the solution exists and "NO" otherwise.

    You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).

    Example
    input
    4
    5 2 5 3 1
    3 0 0 0 0
    4 4 1 4 0
    2 1 1 1 1
    
    output
    YES
    YES
    NO
    YES
    
    Note

    Here are possible solutions to testcases 11, 22 and 44:

  • 相关阅读:
    sharepoint 2007 升级到 sharepoint 2013
    sharepoint 2010中启用RBS及所遇问题
    sharepoint 读取文件夹中所有的数据
    脚本设置ip&自动获取ip
    window 2008 r2 每隔一小时都要重启一次解决办法
    sharepoint 弹出框
    sharepoint powershell 根据报错的GUID查询错误
    java中switch选择结构
    mysql查看表字段相关信息
    mac系统 -postman发送http请求
  • 原文地址:https://www.cnblogs.com/la-la-wanf/p/14473245.html
Copyright © 2011-2022 走看看