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 教你写一个可以搞炸本机所有 WCF 应用的程序方法
作为团队里面挖掘机出身的我,怎么能不多挖一些坑好将小伙伴们都埋进去呢.本文来告诉大家一个有趣且简单的方法,此方法可以将本机的 WCF 玩坏,不敢说真的搞炸本机所有 WCF 应用,但搞炸大部分基于 WC ...
- SQL server 查看脚本
原文出处:http://blog.csdn.net/xiaochunyong/article/details/7455051 --Siuon --查看存储过程源码 create procedure m ...
- k8s应用---持久化存储和StorageClass(10)
一.简介: 在 k8s 中为什么要做持久化存储? 在 k8s 中部署的应用都是以 pod 容器的形式运行的,假如我们部署 MySQL.Redis 等数据库,需要 对这些数据库产生的数据做备份.因为 P ...
- 【Nano Framework ESP32篇】使用 LCD 屏幕
在开始主题之前,先介绍一个刷固件工具.这个工具在 idf 中是集成的,不过,乐鑫也单独发布了这个工具-- esptool.下载链接:Releases · espressif/esptool · Git ...
- Solution Set - 加训 CF!
加训一些 CF 题,这里写一些简要题解,可能是草稿. 暂定只做 Div.1 的题和 Div.1+Div.2 的后一半题.
- python3使用dpkt生成PCMA格式rtp流
操作系统 :CentOS 7.6_x64 Python版本:3.9.12 dpkt版本:1.9.8 PCMA编码是VoIP通信中常见的格式,今天整理下CentOS7环境下,python3如何使用dpk ...
- Git——关于Git的一些补充(1)
Git--关于Git的一些补充(1) 提示:图床在国外且动图比较多的情况下,需要时间加载. 目录: 目录 Git--关于Git的一些补充(1) 提示:图床在国外且动图比较多的情况下,需要时间加载. 目 ...
- C数据结构:KMP算法详解(呕心沥血)
KMP算法 作者心声 了解暴力求解(必需会) KMP算法详解 记住我这段话(你会爱上它的)← : ①前后缀及其用处 ②求出前后缀的next数组 求出next数组的代码 开始实现KMP算法 结尾 附上源 ...
- angular打包优化
打包生产环境时需要的配置如下: 在angular.json里的"configurations"里配置: "configurations": { "pr ...
- sql审计平台部署
其它数据库管理平台:Orchestrator部署 包链接:https://github.com/hhyo/Archery/tree/master 部署链接:https://github.com/hhy ...