题解:P12606 碰碰车大战
题解:P12606 碰碰车大战
我原本以为我恐吓了肚子的,肚子的应该躲在机房,不敢找我,可正当这时,我听见了音乐声,原来是我洛谷私信响了,一看,竟然是写出
-
- 每道题思维含量都超过我的脑容量。
形式化地,需要满足:
-
\footnotesize{\texttt{I won't tell you that it took me one hour to finish this problem.}} -
\footnotesize{\texttt{Why am I so foolish at this?}}
后来,他写出出了
50 道思维绿题(6/50)。
SPJ 用来做什么?
思考
题目大意
要求构造
- 每个数都在
[1, n] 的区间; - 对于任意两个元组
p 和q ,一定存在两个元素p_i 和q_j ,使得p 删除p_i 并且q 删除q_j 之后,元组p 和q 仍不相同。
思路历程
很巧妙的构造。
我的注意力惊人,注意到了数据范围中的
这意味着,如果题目要求我们构造
对于单个元组,任意一个元素有
这意味着,如果题目按上述要求的话,我们只需随机构造
解决
正确思路
但题目要的是
但我的注意力依旧惊人,注意到了条件
条件
因为在删除任意一对数之后,仍有另一对数使得
再仔细思考,我们发现,上面的思路仍有一个小漏洞。
我们填充前
这时,该借鉴 MixxxxTion(实睿性黄真名轩)巨佬的想法了。
注意到我们仅填充了前
那怎么使任意两个元组的第
很容易想到同余。
对于任意两个
我们令
此时,我们删除
- 如果
p_i = q_j ,但因为元组本身互不相同,删除相同的元素后本身仍不相同,故满足条件; - 如果
p_i \neq q_j ,但因为同余定理,\sum^{m}_{i = 1} p - p_i \not\equiv \sum^{m}_{i = 1} q - q_j ,所以最后一位仍是不同的,故依然满足条件。
恭喜你,找出了正解构造!
对于每个
不对,还有一个问题,怎么构造前
作者太区了,他以开始想的是 DFS 枚举前
观察题解区,我的注意力并没有衰减,注意到“
CODE
::::success[AC Code]
#include<bits/stdc++.h>
//#include<windows.h>
//#include<mmsystem.h>
#define int long long
#define ULL unsigned long long
#define double long double
#define PII pair<int, int>
#define PQ priority_queue
#define LLinf 0x3f3f3f3f3f3f3f3f
#define eps 1e-9
//#define inverse_of_times_2_and_mod_998244353 499122177
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while(ch > 57 || ch < 48) {
if(ch == 45) {
f = -1;
}
ch = getchar();
}
while(ch >= 48 && ch <= 57) {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
int n, m, k;
signed main(){
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
n = read();
m = read();
k = read();
for(int i = 1; i <= k; i ++) {
int tmp = i;
int sum = 0;
for(int j = 1; j < m; j ++) {
cout << tmp % n + 1 << ' ';
sum += tmp % n + 1;
tmp /= n;
}
cout << sum % n + 1 << endl;
}
return 0;
}
//TODO
//I AKed IOI !!!