1004_Decomposition
题意: 给一个奇数顶点的完全图, 要求输出k条长度分别为 l i l_i li 的不相交简单路径 ( l i ≤ n − 3 l_i \leq n - 3 li≤n−3 , ∑ l = n × ( n − 1 ) 2 \sum l = \frac{n \times (n - 1)}{2} ∑l=2n×(n−1))
刚开始漏掉了简单路径的条件(…
直接用欧拉回路切割然后喜提几发wa
后面就一直在构造相邻顶点间隔大于n -3 的欧拉回路,简直了我还搜了几篇论文
看图就知道怎么构造了:
按上述图构造的欧拉回路:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int a[N];
signed main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
n--;
for (int i = 0; i < n; ++i) {
a[i] = i + 2;
}
vector<int> res;
res.push_back(1);
for (int tt = 0; tt < n / 2; ++tt) {
int l = tt, r = (tt - 1 + n) % n;
res.push_back(a[l]);
l = (l + 1) % n;
for (int mm = 0; mm < (n - 2) / 2; ++mm) {
res.push_back(a[l]);
l = (l + 1) % n;
res.push_back(a[r]);
r = (r - 1 + n) % n;
}
res.push_back(a[l]);
res.push_back(1);
}
for (auto x : res) {
cout << x << " ";
}
cout << endl;
}
}
这题代码:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int a[N];
signed main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int T, cas = 0;
cin >> T;
while (T--) {
cout << "Case #" << ++cas << ":" << endl;
int n, m;
cin >> n >> m;
n--;
for (int i = 0; i < n; ++i) {
a[i] = i + 2;
}
vector<int> res;
res.push_back(1);
for (int tt = 0; tt < n / 2; ++tt) {
int l = tt, r = (tt - 1 + n) % n;
res.push_back(a[l]);
l = (l + 1) % n;
for (int mm = 0; mm < (n - 2) / 2; ++mm) {
res.push_back(a[l]);
l = (l + 1) % n;
res.push_back(a[r]);
r = (r - 1 + n) % n;
}
res.push_back(a[l]);
res.push_back(1);
}
// for (auto x : res) {
// cout << x << " ";
// }
// cout << endl;
int idx = 0;
while (m--) {
int len;
cin >> len;
cout << res[idx];
for (int i = 1; i <= len; ++i) {
cout << " " << res[idx + i];
}
idx += len;
cout << endl;
}
}
}