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, ...
随机推荐
- PF4J使用
PF4J是一个Java轻量级的插件框架,可以实现动态加载,执行,卸载外部插件(支持jar以及zip),具体可以看官网:https://pf4j.org/. 本文例子基于Github地址:https:/ ...
- JavaWeb 11_文件上传
一.操作步骤 1.要有一个form标签,method=post 请求2.form标签的encType属性值必须为multipart/form-data值3.在form标签中使用input type=f ...
- Linux-Centos7学习笔记
镜像下载.域名解析.时间同步请点击阿里云开源镜像站 下载.安装与配置 下载 下载Centos镜像,网站见参考 点击大的版本,例如7,再选择isos进行下载 安装 这里使用的VMware 12 Pro, ...
- kubernetes内yaml格式
yaml格式的pod定义文件完整内容: apiVersion: v1 #必选,版本号,例如v1 可通过 kubectl api-versions 获取 kind: Pod #必选,Pod metada ...
- Flask 之 WebSocket
http:是一个协议 规定:数据传输格式 -/r/n/r/n 一次的请求,一次的响应,断开了 短链接 无状态 服务器收到的请求,做出的响应给客户端 客户端主动向服务器发起请求 基于socket sen ...
- BGP的五种报文六种状态
BGP的五种报文 Open报文:用于协商BGP参数,包括版本号,AS号等信息.在两个路由器之间建立了TCP会话之后开始交换Open信息以确认是否能形成邻居关系,是TCP建立后发送的第一个信息,类似OS ...
- 不重写hash不重写equals造成的问题
不重写hash造成的问题 第一,就是不重写,调用object 的hashCode方法,用的是地址, 比如现在你map.put() 10000个对象,这时候对象都是不同的地址,计算出不同的对应的桶位置( ...
- (转)String,StringBuilder,StringBuffer区别
Java中的String,StringBuilder,StringBuffer三者的区别 注:转自-博客园-酥风 最近在学习Java的时候,遇到了这样一个问题,就是String,StringBuild ...
- react核心?
虚拟DOM, Diff算法, 遍历key值 react-dom: 提供了针对DOM的方法,比如:把创建的虚拟DOM,渲染到页面上 或 配合ref来操作DOM react-router
- Ajax的乱码解决问题?
Javascript是使用UTF-8国际编码,即每个汉字用4个字节来存储,这就造成了用AJAX来send数据的时候出现会乱码. Ajax乱码产生主要有2个原因 1. XMLHttpRequest返回的 ...