2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest (Online Mirror, ICPC Rules, Teams Preferred) M. SmartGarden 题解
cf1250 M. SmartGarden
完全不会做 orz,在 cf 上看到了有趣的做法。
通读题意后可以发现是对于每一次操作,要求选出的行集合 \(R\) 和列集合 \(C\) 要满足如下条件:
\]
接下来考虑二进制下对每一次操作如何取行集合和列集合。枚举二进制下每一位 \(i\),把所有当前位 \(i=0\) 的行 \(r\) 加入行集合 \(R\) 中,同时将所有当前位 \(i=1\) 以及 \(c+1\) 的当前位也为 \(i=1\) 的列 \(c\) 加入列集合 \(C\) 中,这样就是一次操作。反过来可以把所有当前位 \(i=1\) 的行 \(r\) 加入行集合 \(R\) 中,同时将所有当前位 \(i = 0\) 以及 \(c+1\) 的当前位也为 $i = 0 $ 的列 \(c\) 加入列集合 \(C\) 中,这样又是一次操作。这样共计 \(2 \cdot \lceil \log_2 5000 \rceil = 2 \cdot 13 = 26\) 次操作。这样的操作必定满足上面的条件。问题变为了如何填满漏选的地方。
观察一下列 \(c\) 的格式,可以发现其形如 \(XX...X011...1\) ,前面的 \(X\) 为固定位,后面的 \(011...1\) 为翻转位,\(c+1\) 与 \(c\) 的固定位相同,而翻转位每一位都不同。若 \((r,c)\) 漏选,可以得出 \(r\) 与 \(c\) 的固定位相同的结论。这是一个充要条件。
那么,枚举后面的翻转位的长度,并将所有翻转位都为该长度的列 \(c\) 加入本次的列集合 \(C\) 中。而关于行 \(r\) ,只要其二进制下与列 \(c\) 翻转位对应的位不为 \(011...1\) 或 \(100...0\) 即可满足条件。这样也会有 \(\lceil \log_2 5000 \rceil = 13\) 次操作。故最大操作数为 \(39\)。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ld;
#define IL inline
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define dbg1(x) cout << #x << " = " << x << ", "
#define dbg2(x) cout << #x << " = " << x << endl
template<typename Tp> IL void read(Tp &x) {
x=0; int f=1; char ch=getchar();
while(!isdigit(ch)) {if(ch == '-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
x *= f;
}
int buf[42];
template<typename Tp> IL void write(Tp x) {
int p = 0;
if(x < 0) { putchar('-'); x=-x;}
if(x == 0) { putchar('0'); return;}
while(x) {
buf[++p] = x % 10;
x /= 10;
}
for(int i=p;i;i--) putchar('0' + buf[i]);
}
const int N = 5000 + 5;
int n;
vector<vector<int> > rows, cols;
IL bool chkbit(int x, int p) { return (x & (1 << p)) > 0;}
int main() {
#ifdef LOCAL
freopen("M.in", "r", stdin);
#endif
scanf("%d", &n);
for(int bt=0;bt<=1;bt++) {
for(int i=0; (1<<i) <= n; i++) {
vector<int> row, col;
for(int k=1;k<=n;k++) {
if(chkbit(k, i) == bt) row.push_back(k);
else if(k == n || chkbit(k+1, i) != bt) col.push_back(k);
}
if(row.empty() || col.empty()) continue;
rows.push_back(row);
cols.push_back(col);
}
}
for(int i=1; (1<<i)-1 <= n; i++) {
int flip = (1 << i) - 1;
int flip2 = (flip << 1) | 1;
int isrow = (1 << i);
vector<int> row, col;
for(int j=1;j<=n;j++) {
if((j & flip) == flip && (j & flip2) != flip2) col.push_back(j); // XX...X011...1
else if((j & flip2) != isrow) row.push_back(j);
}
if(col.empty() || row.empty()) continue;
rows.push_back(row);
cols.push_back(col);
}
printf("%d\n", SZ(rows));
for(int i=0;i<SZ(rows);i++) {
printf("%d ", SZ(rows[i]));
for(int j=0;j<SZ(rows[i]);j++) {
printf("%d%c", rows[i][j], " \n"[j == SZ(rows[i]) - 1]);
}
printf("%d ", SZ(cols[i]));
for(int j=0;j<SZ(cols[i]);j++) {
printf("%d%c", cols[i][j], " \n"[j == SZ(cols[i]) - 1]);
}
}
return 0;
}
2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest (Online Mirror, ICPC Rules, Teams Preferred) M. SmartGarden 题解的更多相关文章
- 2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)【A题 类型好题】
A. Berstagram Polycarp recently signed up to a new social network Berstagram. He immediately publish ...
- 2020-2021 ICPC, NERC, Southern and Volga Russian Regional Contest (Online Mirror, ICPC Rules) D. Firecrackers (贪心,二分)
题意:有个长度为\(n\)的监狱,犯人在位置\(a\),cop在位置\(b\),你每次可以向左或者向右移动一个单位,或者选择不动并在原地放一个爆竹\(i\),爆竹\(i\)在\(s[i]\)秒后爆炸, ...
- 2020-2021 ICPC, NERC, Southern and Volga Russian Regional Contest (Online Mirror, ICPC Rules) C. Berpizza (STL)
题意:酒吧里有两个服务员,每个人每次都只能服务一名客人,服务员2按照客人进酒吧的顺序服务,服务员3按照客人的钱来服务,询问\(q\),\(1\)表示有客人进入酒吧,带着\(m\)块钱,\(2\)表示询 ...
- 2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest
目录 Contest Info Solutions A. Berstagram B. The Feast and the Bus C. Trip to Saint Petersburg E. The ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution
A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$< ...
- Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结
第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...
- codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解
秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
A 思路: 贪心,每次要么选两个最大的,要么选三个,因为一个数(除了1)都可以拆成2和3相加,直到所有的数都相同就停止,这时就可以得到答案了; C: 二分+bfs,二分答案,然后bfs找出距离小于等于 ...
- 2014-2015 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
I. Sale in GameStore(贪心) time limit per test 2 seconds memory limit per test 512 megabytes input sta ...
随机推荐
- dotnet 解析 TTF 字体文件格式
在 Windows 下,可以使用 DX 提供的强大能力,调用 DX 读取 TTF 字体文件,获取字体文件的信息以及额外的渲染信息.特别是基于 DX 的 WPF 更是加了一层封装,使用 FontFami ...
- CMDB开发(三)
6.API验证 # 加密复习 #1.简单的对称加密,token是固定的 客户端请求: import requests # 1.自定义token值 token = 'cxiong_token' # to ...
- (数据科学学习手札160)使用miniforge代替miniconda
本文已收录至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 大家好我是费老师,conda作为Python数据科学领域 ...
- vue点击旋转,再点击复原
效果: 1.html.通过绑定t值控制不同的class名, 原图是右边方向的箭头 <img class="right" v-if="item.t" src ...
- SAP Adobe Form 教程一 简单示例
马上需要用到adobe form,这里搬运一篇教程学习下. 英文原文:SAP Adobe Interactive Form Tutorial. Part I. First Adobe Form 本文链 ...
- tomcat(2)- tomcat目录结果和配置文件
目录 1 Tomcat目录结构 2 Tomcat的配置文件 2.1 server.xml配置文件 2.2 server.xml配置文件结构 2.3 WEB应用自动部署 2.4 配置文件各个组件的关联 ...
- windows下安装Psycopg2,用于python连接postgresql
1.首先,下载Windows版的Psycopg2.进入https://pypi.python.org/pypi/psycopg2/ ,在下载文件列表中选择psycopg2-2.7.4-cp33-cp3 ...
- mybaits-plus实现自定义字典转换
需求:字典实现类似mybatis-plus中@EnumValue的功能,假设枚举类中应用使用code,数据库存储对应的value 思路:Mybatis支持对Executor.StatementHand ...
- PyQt5自定义信号
一.简介 在 PyQt5 中,自定义信号是一个常见的任务,通常用于在对象之间传递信息或触发特定行为.自定义信号需要继承自 QtCore.pyqtSignal 并定义其参数类型. 二.操作步骤 1.导入 ...
- EF CORE 命令行
EF 命令行 使用管理台模式 Add-Migration 添加一个新的迁移(名词),string是迁移的名称remove-Migration 删除上一次的迁移Update-Database 更新最近一 ...