当前位置: 首页> 汽车> 维修 > 深圳宝安疫情最新消息_沈阳男科医院在哪里_小程序推广引流_跨境电商seo什么意思

深圳宝安疫情最新消息_沈阳男科医院在哪里_小程序推广引流_跨境电商seo什么意思

时间:2025/8/28 18:15:11来源:https://blog.csdn.net/qq_61422664/article/details/147031178 浏览次数: 0次
深圳宝安疫情最新消息_沈阳男科医院在哪里_小程序推广引流_跨境电商seo什么意思

C. You Soared Afar With Grace

题目:

思路:

很有意思的模拟题,代码细节需注意

因为题目没要求我们最小步骤什么的,同时n也比较小,所以按照题意模拟即可,但是注意细节,比如数的位置,奇偶性,特殊情况等

代码:

#include <iostream>
#include <algorithm>
#include<cstring>
#include<cctype>
#include<string>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <memory>
using namespace std;
#define int long long
#define yes cout << "YES\n"
#define no cout << "NO\n"void solve()
{int n;cin >> n;vector<int> a(n+1),b(n+1);vector<int> bpos(n+1,0);for (int i = 1; i <= n; i++){cin >> a[i];}int flag = 0;for (int i = 1; i <= n; i++){cin >> b[i];flag |= (b[i] != a[n+1 - i]);bpos[b[i]] = i;}if (!flag){cout << "0\n";return;}int num = 0;vector<pair<int, int>> ans;for (int i = 1; i <= n; i++){if (a[bpos[a[i]]] != b[i]){cout << "-1\n";return;}if (a[i] == b[i]){if (n % 2 == 0 || num){cout << "-1\n";return;}num = i;}}auto change = [&](int x,int y) {if (x == y){return;}ans.push_back({ x,y });swap(a[x], a[y]);swap(b[x], b[y]);swap(bpos[b[x]], bpos[b[y]]);};if (num){change(num, (n + 1) / 2);}for (int i = 1; i <= n / 2; i++){change(bpos[a[i]], n + 1 - i);}cout << ans.size() << endl;for (auto x : ans)wcout << x.first << " " << x.second << endl;
}signed main()
{cin.tie(0)->sync_with_stdio(false);int t = 1;cin >> t;while (t--){solve();}return 0;
}

D. Arcology On Permafrost

题目:

思路:

需要一点观察的构造题

 我们最优的解法肯定是构造出一个类似与于 0 1 2 ... d 0 1 2 ... d 0 1 ... 这样的序列,其中任意一个数字都要出现 m + 1 次,这样才能保证最后能剩下这个数,同时相同的数一定要间隔 k ,这样才能保证不会一次删除两个的情况

所以这个 d 的最大值就是 n / (m + 1) - 1 (要包含0),间隔就是 max(d,k)

代码还是很好写的

代码:

#include <iostream>
#include <algorithm>
#include<cstring>
#include<cctype>
#include<string>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <memory>
using namespace std;
#define int long long
#define yes cout << "YES\n"
#define no cout << "NO\n"void solve()
{int n, m, k;cin >> n >> m >> k;vector<int> ans(n);int d = n / (m + 1);for (int i = 0; i < d; ++i) {for (int j = i; j < n; j += max(k, d)){ans[j] = i;}}for (int i = 0; i < n; ++i) {cout << ans[i] << " ";}cout << endl;
}signed main()
{cin.tie(0)->sync_with_stdio(false);int t = 1;cin >> t;while (t--){solve();}return 0;
}

关键字:深圳宝安疫情最新消息_沈阳男科医院在哪里_小程序推广引流_跨境电商seo什么意思

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: