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. WPF 如何知道当前有多少个 DispatcherTime 在运行

    在 WPF 调试中,对于 DispatcherTimer 定时器的执行,没有直观的调试方法.本文来告诉大家如何在 WPF 中调试当前主线程有多少个 DispatcherTimer 在运行 在 WPF ...

  2. Qt Quick 工程创建

    一.简介 Qt Quick是Qt框架中的一个模块,用于创建现代.响应式的用户界面.它基于QML(Qt Meta-Object Language)语言和Qt Quick Controls库,提供了一种声 ...

  3. M9K内存使用教程

    M9K内存使用教程 M9K内存是Altera内嵌的高密度存储阵列.现代的FPGA基本都包含类似的不同大小的内存. M9K的每个块有8192位(包含校验位实际是9216位).配置灵活.详细了解M9K可参 ...

  4. 自定义Naive UI的数据表格Data Table中按钮Button图标

    在Naive UI官网中详细介绍了[数据表格 Data Table](数据表格 Data Table - Naive UI)的使用方式 { title: "Action", key ...

  5. swagger 的配置

    1,开启swagger : c.IncludeXmlComments(GetXmlCommentsPath()); protected static string GetXmlCommentsPath ...

  6. golang import 导入的四种方式

    1 标准导入: import "package_name" 2 导入别名: import ( alias "package_name" ) 3 匿名导入: _ ...

  7. 分享5款.NET开源免费的Redis客户端组件库

    前言 今天大姚给大家分享5款.NET开源.免费的Redis客户端组件库,希望可以帮助到有需要的同学. StackExchange.Redis StackExchange.Redis是一个基于.NET的 ...

  8. ChatTTS,语气韵律媲美真人的开源TTS模型,文字转语音界的新魁首,对标微软Azure-tts

    前两天 2noise 团队开源了ChatTTS项目,并且释出了相关的音色模型权重,效果确实非常惊艳,让人一听难忘,即使摆在微软的商业级项目Azure-tts面前,也是毫不逊色的. ChatTTS是专门 ...

  9. NOIP模拟55

    T1 Skip 解题思路 正解给的是线段树维护单调栈,但是我不会.. CDQ 维护斜率可做!!! 先得出一个朴素的 DP 方程:设 \(f_i\) 表示最后一场是 i 的最优解. 转移方程就是 \(f ...

  10. 解决TrueNAS中Smb共享文件路径不区分大小写的问题

    问题 在Truenas中, 默认的smb文件分享中, 文件夹是不区分大小写的. 这在一些情况下会导致无法重命名等问题, 严重时可能会造成拷贝文件时的全文件夹文件丢失. 这是linux下的情况, 在已存 ...