Solution -「ARC 104C」Fair Elevator
\(\mathcal{Description}\)
Link.
数轴从 \(1\sim 2n\) 的整点上有 \(n\) 个闭区间。你只知道每个区间的部分信息(可能不知道左或右端点,或者都不知道),问是否存在满足已知信息的 \(n\) 个区间,满足:
- 每个整点是恰好一个区间的端点。
- 所有包含同一个整点的区间长度相等。
输入信息可能不合法。
\(n\le100\)。
\(\mathcal{Solution}\)
老细节题了。(
考虑数轴上连续的一段区间 \([l,r]\),记 \(L=r-l+1\),若该区间内能够满足条件,则显然有:
- \(2|L\)。
- \([i,i+\frac{L}2]\) 可以存在于区间集合中。
记 \(f(i)\) 表示 \(1\sim i\) 能否合法,\(\mathcal O(n^3)\) 暴力转移即可。
但这个不是难点,if-else 才是难点 qwq。
- 输入可能多点重合,判否。
- 若有区间 \([l,?]\) 和 \([?,r]\),注意不能让 \(l\) 和 \(r\) 组成 \([l,r]\)。
对于第二点,一组 CF 上的 hack 数据为:
2
1 -1
-1 3
answer: No
多堆几个 if-else 就 A 啦!(
\(\mathcal{Code}\)
/* Clearink */
#include <cstdio>
#include <cstdlib>
#include <assert.h>
const int MAXN = 200;
int n, match[MAXN + 5];
bool f[MAXN + 5], vis[MAXN + 5];
inline bool check ( const int l, const int r ) {
int stp = r - l + 1 >> 1; // i -> i + stp.
for ( int i = l, j; ( j = i + stp ) <= r; ++ i ) {
bool acci = 1 <= match[i] && match[i] <= n << 1;
bool accj = 1 <= match[j] && match[j] <= n << 1;
if ( match[i] == -1 || ( acci && match[i] ^ j )
|| match[j] == ( n << 1 | 1 ) || ( accj && match[j] ^ i )
|| ( !acci && !accj && match[i] && match[j] ) ) {
return false;
}
}
return true;
}
int main () {
scanf ( "%d", &n );
for ( int i = 1, a, b; i <= n; ++ i ) {
scanf ( "%d %d", &a, &b );
if ( ~a && ~b && a >= b ) return puts ( "No" ), 0;
if ( ~a && ~b ) match[a] = b, match[b] = a;
else if ( ~a ) match[a] = n << 1 | 1;
else if ( ~b ) match[b] = -1;
if ( ~a ) {
if ( vis[a] ) return puts ( "No" ), 0;
vis[a] = true;
}
if ( ~b ) {
if ( vis[b] ) return puts ( "No" ), 0;
vis[b] = true;
}
}
f[0] = true;
for ( int i = 2; i <= n << 1; i += 2 ) {
for ( int j = 0; j < i && !f[i]; j += 2 ) {
f[i] = f[j] && check ( j + 1, i );
}
}
puts ( f[n << 1] ? "Yes" : "No" );
return 0;
}
Solution -「ARC 104C」Fair Elevator的更多相关文章
- Solution -「ARC 104E」Random LIS
\(\mathcal{Description}\) Link. 给定整数序列 \(\{a_n\}\),对于整数序列 \(\{b_n\}\),\(b_i\) 在 \([1,a_i]\) 中等概率 ...
- Solution -「ARC 101D」「AT4353」Robots and Exits
\(\mathcal{Description}\) Link. 有 \(n\) 个小球,坐标为 \(x_{1..n}\):还有 \(m\) 个洞,坐标为 \(y_{1..m}\),保证上述坐标 ...
- Solution -「ARC 110D」Binomial Coefficient is Fun
\(\mathcal{Description}\) Link. 给定非负整数序列 \(\{a_n\}\),设 \(\{b_n\}\) 是一个非负整数序列且 \(\sum_{i=1}^nb_i\ ...
- Solution -「ARC 124E」Pass to Next
\(\mathcal{Description}\) Link. 有 \(n\) 个人站成一个环,初始时第 \(i\) 个人手里有 \(a_i\) 个球.第 \(i\) 个人可以将自己手中任意数 ...
- Solution -「ARC 126E」Infinite Operations
\(\mathcal{Description}\) Link. 给定序列 \(\{a_n\}\),定义一次操作为: 选择 \(a_i<a_j\),以及一个 \(x\in\mathbb R ...
- Solution -「ARC 126F」Affine Sort
\(\mathcal{Description}\) Link. 给定 \(\{x_n\}\),令 \[f(k)=\left|\{(a,b,c)\mid a,b\in[0,c),c\in[1,k ...
- Solution -「ARC 125F」Tree Degree Subset Sum
\(\mathcal{Description}\) Link. 给定含有 \(n\) 个结点的树,求非负整数对 \((x,y)\) 的数量,满足存在 \(\exist S\subseteq V ...
- Solution -「ARC 125E」Snack
\(\mathcal{Description}\) Link. 把 \(n\) 种零食分给 \(m\) 个人,第 \(i\) 种零食有 \(a_i\) 个:第 \(i\) 个人得到同种零食数量 ...
- Solution -「ARC 058C」「AT 1975」Iroha and Haiku
\(\mathcal{Description}\) Link. 称一个正整数序列为"俳(pái)句",当且仅当序列中存在连续一段和为 \(x\),紧接着连续一段和为 \(y ...
随机推荐
- Apache Ant: If 和 Unless
目录 If And Unless If And Unless 从 Ant 1.9.1 起,可以在所有的任务和嵌套的元素上以特别的命名空间添加 if 和 unless 属性. In order to u ...
- spring boot 中使用swagger
一.pom.xml <dependency> <groupId>io.springfox</groupId> <artifactId>springfox ...
- 有道翻译js加密参数分析
平时在渗透测试过程中,遇到传输的数据被js加密的比较多,这里我以有道翻译为例,来分析一下它的加密参数 前言 这是有道翻译的界面,我们随便输入一个,抓包分析 我们发现返回了一段json的字符串,内容就是 ...
- 《剑指offer》面试题46. 把数字翻译成字符串
问题描述 给定一个数字,我们按照如下规则把它翻译为字符串:0 翻译成 "a" ,1 翻译成 "b",--,11 翻译成 "l",--,25 ...
- 【解决了一个小问题】vmselect对应的vmstorage端口配置错误导致的问题
从vmselect查询的时候,出现如下错误: error when executing query="up" on the time range (start=1639388706 ...
- X架构键盘选购指南
X架构键盘 联想 JME8002(未知) JME7597(推荐) 据说是ThinkPAD键盘的血统. Thinkapad 小红点键盘,据说腿撑容易坏 明基 明基精钢侠 海湾海贝(键程长,不累手,但不易 ...
- gin中的文件上传
1. 单文件上传 package main import ( "fmt" "github.com/gin-gonic/gin" "log" ...
- Servlet-通过继承HttpServlet类实现Servlet程序
通过继承HttpServlet类实现Servlet程序(开发一般用) 一般在实际项目开发中,都是使用继承 HttpServlet类的方式实现Servlet程序 1,编写一个类去继承 HttpServl ...
- Web安全防护(二)
点击劫持 点击劫持,也称UI覆盖攻击 1.1 iframe覆盖攻击 黑客创建一个网页,用iframe包含了目标网站,并且把它隐藏起来.做一个伪装的页面或图片盖上去,且按钮与目标网站一致,诱导用户去点击 ...
- db2服务器linux的cache过高原因
在线上db2数据库服务器,使用的linux操作系统(RHEL,centos),当db2数据库运行一段时间之后,操作系统的物理内存就趋近于0,同时系统的cache暴增,但是use却不高,下面是正常使用 ...