Educational Codeforces Round 117 (Rated for Div. 2) ABCD
Posted 嗯我想想
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 117 (Rated for Div. 2) ABCD相关的知识,希望对你有一定的参考价值。
A. Distance
B. Special Permutation
C. Chat Ban
D. X-Magic Pair
A. Distance
思路分析
读懂题意,分情况讨论一下即可
AC代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int T;
int main()
cin >> T;
while (T--)
int x, y;
cin >> x >> y;
if ((x + y) % 2 != 0)
cout << "-1 -1" << endl;
else
if (y > x)
cout << 0 << " " << (x + y) / 2 << endl;
else
cout << (x + y) / 2 << " " << 0 << endl;
B. Special Permutation
思路分析
先判断-1的情况,剩下的就比较好处理了
AC代码
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, char> PII;
typedef long long ll;
const int N = 2e5 + 10;
int T;
int n, a, b;
vector<int> l;
vector<int> r;
void solve()
l.clear();
r.clear();
cin >> n >> a >> b;
if ((a <= n / 2 && b <= n / 2) || (a > n / 2 && b > n / 2))
cout << -1 << endl;
return;
if (a > b)
if (a - b > 1)
cout << -1 << endl;
return;
else
for (int i = n; i >= 1; i--)
cout << i << ' ';
cout << endl;
return;
if (a < b)
l.push_back(a);
r.push_back(b);
for (int i = n; i > n / 2; i--)
if (i != b)
l.push_back(i);
for (int i = 1; i <= n / 2; i++)
if (i != a)
r.push_back(i);
for (auto item = l.begin(); item != l.end(); item++)
cout << *item << ' ';
for (auto item = r.begin(); item != r.end(); item++)
cout << *item << ' ';
cout << endl;
int main()
cin >> T;
while (T--)
solve();
return 0;
C. Chat Ban
思路分析
其实就是三角形的两半,分上下两块三角形进行二分查找即可
AC代码
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, char> PII;
typedef long long ll;
const int N = 2e5 + 10;
int T;
ll x, k;
void solve()
cin >> k >> x;
if (k * k <= x)
cout << 2 * k - 1 << endl;
return;
// 1 到 n 求和
ll sum = (k * (k + 1)) / 2;
int ans = 0;
// 三角形上半部分
if (x <= sum)
ll l = 1, r = k;
ll m;
while (l <= r)
m = l + (r - l) / 2;
if ((m * (m + 1)) / 2 >= x)
ans = m;
r = m - 1;
else
l = m + 1;
else
// 三角形下半部分
x -= sum;
sum = (k * (k - 1)) / 2;
ll l = 0, r = k - 1;
ll m;
while (l <= r)
m = l + (r - l) / 2;
ll ch = (m * (m + 1)) / 2;
if (sum - ch < x)
ans = m;
r = m - 1;
else
l = m + 1;
ans = 2 * k - ans;
cout << ans << endl;
int main()
cin >> T;
while (T--)
solve();
return 0;
D. X-Magic Pair
思路分析
这个题是队友给的一个大概思路,当时距离答案已经比较接近了,我回来后改了一下条件就A了,后来想想有点像找规律QAQ
AC代码
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, char> PII;
typedef long long ll;
const int N = 2e5 + 10;
int T;
ll x, a, b;
int gcd(ll a, ll b, ll x)
if (b == 0)
return 0;
if (a < x)
return 0;
if ((a - x) % b == 0)
return 1;
if(gcd(b, a % b, x))
return 1;
return 0;
int solve()
cin >> a >> b >> x;
if (x > a && x > b)
return 0;
if (a == b)
if (a != x)
return 0;
else
return 1;
else
if(a < b)
swap(a,b);
return gcd(a, b, x);
int main()
cin >> T;
while (T--)
if (solve())
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
以上是关于Educational Codeforces Round 117 (Rated for Div. 2) ABCD的主要内容,如果未能解决你的问题,请参考以下文章
Educational Codeforces Round 7 A
Educational Codeforces Round 7
Educational Codeforces Round 90
Educational Codeforces Round 33