cf1250 M. SmartGarden

完全不会做 orz,在 cf 上看到了有趣的做法。

通读题意后可以发现是对于每一次操作,要求选出的行集合 \(R\) 和列集合 \(C\) 要满足如下条件:

\[(\forall r)(\forall c)(r \in R \wedge c \in C \wedge r \neq c \wedge r \neq c+1)
\]

接下来考虑二进制下对每一次操作如何取行集合和列集合。枚举二进制下每一位 \(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 题解的更多相关文章

  1. 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 ...

  2. 2020-2021 ICPC, NERC, Southern and Volga Russian Regional Contest (Online Mirror, ICPC Rules) D. Firecrackers (贪心,二分)

    题意:有个长度为\(n\)的监狱,犯人在位置\(a\),cop在位置\(b\),你每次可以向左或者向右移动一个单位,或者选择不动并在原地放一个爆竹\(i\),爆竹\(i\)在\(s[i]\)秒后爆炸, ...

  3. 2020-2021 ICPC, NERC, Southern and Volga Russian Regional Contest (Online Mirror, ICPC Rules) C. Berpizza (STL)

    题意:酒吧里有两个服务员,每个人每次都只能服务一名客人,服务员2按照客人进酒吧的顺序服务,服务员3按照客人的钱来服务,询问\(q\),\(1\)表示有客人进入酒吧,带着\(m\)块钱,\(2\)表示询 ...

  4. 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 ...

  5. 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, ...

  6. 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$ 思路: 定义一个二元组$< ...

  7. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

  8. codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解

    秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...

  9. 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    A 思路: 贪心,每次要么选两个最大的,要么选三个,因为一个数(除了1)都可以拆成2和3相加,直到所有的数都相同就停止,这时就可以得到答案了; C: 二分+bfs,二分答案,然后bfs找出距离小于等于 ...

  10. 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 ...

随机推荐

  1. xtrabackup备份恢复

    tar -xzvf percona-xtrabackup-2.1.9-744-Linux-x86_64.tar.gz cd percona-xtrabackup-2.1.9-Linux-x86_64/ ...

  2. python 简明笔记

    python 简明笔记 基础内置类型 数值类型 字面量 3.14e-10 3.14E-10 3.14e+10 #八进制 0o123 #十六进制 0xabf #二进制 0b10101 #进制转换函数 # ...

  3. 03. Ruby入门理解

    Ruby入门学习: 视频教程 https://www.bilibili.com/video/BV1QW411F7rh?t=401&p=1 笔记 https://github.com/haima ...

  4. WEB服务与NGINX(1)-HTTP协议基础

    WEB服务与NGINX(1) 目录 WEB服务与NGINX(1) 1. HTTP协议 1.1 WEB资源 1.2 URI简介 1.3 WEB服务请求处理过程 1.4 HTTP报文结构 1.4.1 re ...

  5. python交教程4:文件操作

    文件操作流程 人类操作一个word流程: 1.找到文件.双击打开 2. 读或修改 3. 保存&关闭 ⽤python操作⽂件也差不多: 只读模式  创建模式  追加模式  遍历文件  图片视频- ...

  6. leaflet 根据一个经纬度及距离角度,算出另外一个经纬度

    /** * 根据一个经纬度及距离角度,算出另外一个经纬度 * @param {*} lng 经度 113.3960698 * @param {*} lat 纬度 22.941386 * @param ...

  7. JDK源码阅读-------自学笔记(四)带标签的break和continues

    "标签"是指后面跟一个冒号的标识符,例如:"label:".对Java来说唯一用到标签的地方是在循环语句之前.而在循环之前设置标签的唯一理由是:我们希望在其中嵌 ...

  8. 前后端分离项目(vue+springboot)集成pageoffice实现在线编辑office文件

    前后端分离项目下使用PageOffice原理图 集成步骤 前端 vue 项目 在您Vue项目的根目录下index.html中引用后端项目根目录下pageoffice.js文件.例如: <scri ...

  9. kubernets之了解Qos等级

    一  Qos的种类 BestEffort(优先级最低) Burstable(中等优先级) Guaranteed(最高优先级) 二  Qos的作用 众所周知,节点上面的limits允许超卖,当节点上面的 ...

  10. IDEA使用——新建WEB项目及WEB项目的运行

    第一步:新建项目 1.2勾选Web Application 1.3填写项目名 第二步:项目配置 2.1在WEB-INF目录下新建 classes 和 lib 目录(过程省略) 2.2将classes目 ...