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;
}
四.
附原题:
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.
The first line contains a single integer tt (1≤t≤100; 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 (2≤n≤100; 2≤n≤100; 0≤U,R,D,L≤n).
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).
4
5 2 5 3 1
3 0 0 0 0
4 4 1 4 0
2 1 1 1 1
YES
YES
NO
YES
Here are possible solutions to testcases 11, 22 and 44:

Edu Cf Round 105 (Div. 2) B. Berland Crossword 1.读懂题, 2. 思维的更多相关文章
- CF Round #551 (Div. 2) D
CF Round #551 (Div. 2) D 链接 https://codeforces.com/contest/1153/problem/D 思路 不考虑赋值和贪心,考虑排名. 设\(dp_i\ ...
- CF Round #510 (Div. 2)
前言:没想到那么快就打了第二场,题目难度比CF Round #509 (Div. 2)这场要难些,不过我依旧菜,这场更是被\(D\)题卡了,最后\(C\)题都来不及敲了..最后才\(A\)了\(3\) ...
- 竞赛题解 - CF Round #524 Div.2
CF Round #524 Div.2 - 竞赛题解 不容易CF有一场下午的比赛,开心的和一个神犇一起报了名 被虐爆--前两题水过去,第三题卡了好久,第四题毫无头绪QwQ Codeforces 传送门 ...
- 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library
题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...
- 水题 Codeforces Round #105 (Div. 2) B. Escape
题目传送门 /* 水题:这题唯一要注意的是要用double,princess可能在一个小时之内被dragon赶上 */ #include <cstdio> #include <alg ...
- CF Round #600 (Div 2) 解题报告(A~E)
CF Round #600 (Div 2) 解题报告(A~E) A:Single Push 采用差分的思想,让\(b-a=c\),然后观察\(c\)序列是不是一个满足要求的序列 #include< ...
- cf Round#273 Div.2
题目链接,点击一下 Round#273 Div.2 ================== problem A Initial Bet ================== 很简单,打了两三场的cf第一 ...
- CF Round #509 (Div. 2)
前言:第一次打\(CF\),因为经验不足以及英语水平很烂,即便在机房大佬的带领下也是花了好久才读懂题目..\(A\)题直到\(11\)分钟才\(A\),题目一共才做了\(4\)题,太菜了.. A. H ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)
Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...
随机推荐
- pthread_once函数
http://blog.csdn.net/lmh12506/article/details/8452659 pthread_once()函数详解 在多线程环境中,有些事仅需要执行一次.通常当初始化应用 ...
- Apache+PHP+Mysql安装手册(Windows)
一,准备安装包 下载地址: Apache:HTTPS://www.apachelounge.com/download/ PHP:http://php.net/downloads.php MySQL h ...
- Sting -- byte[]互转
1.String -->byte[] String str = "中国"; byte[] bys = str.getBytes(); Arrays.toString(bys) ...
- Java使用多线程异步执行批量更新操作
import com.google.common.collect.Lists; import org.apache.commons.collections.CollectionUtils; impor ...
- 利用 ps 怎么显示所有的进程? 怎么利用 ps 查看指定进程的信息?
ps -ef (system v 输出)ps -aux bsd 格式输出ps -ef | grep pid
- 在 Java 中 CycliBarriar 和 CountdownLatch 有什么区别?
CyclicBarrier 可以重复使用,而 CountdownLatch 不能重复使用. Java 的 concurrent 包里面的 CountDownLatch 其实可以把它看作一个计数器, 只 ...
- 如何确保消息正确地发送至 RabbitMQ?如何确保消息接收方消费了消息?
发送方确认模式 将信道设置成 confirm 模式(发送方确认模式),则所有在信道上发布的消息都会被指派一个唯一的 ID.一旦消息被投递到目的队列后,或者消息被写入磁盘后(可持久化的消息),信道会发送 ...
- MySQL_fetch_array 和 MySQL_fetch_object 的区别是 什么?
以下是 MySQL_fetch_array 和 MySQL_fetch_object 的区别: MySQL_fetch_array() – 将结果行作为关联数组或来自数据库的常规数组返回. MySQL ...
- Zookeeper 的典型应用场景?
Zookeeper 是一个典型的发布/订阅模式的分布式数据管理与协调框架,开发人员 可以使用它来进行分布式数据的发布和订阅. 通过对 Zookeeper 中丰富的数据节点进行交叉使用,配合 Watch ...
- 学习Git(二)
常用命令 git add 添加 git status 查看状态 git status -s 状态概览 git diff 对比 git diff --staged 对比暂存区 git commit 提交 ...