目录
A - Treasure Hunt
题目链接https://codeforces.com/problemset/problem/817/A
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false)
#define ok(x) (x>0 && x<150000)
const int mac = 2e5 + 10;
int a[mac], vis[mac];
int main()
{
IOS;
int x1, x2, y11, y2, x, y;
cin >> x1 >> y11 >> x2 >> y2;
cin >> x >> y;
if (abs(y2 - y11) % y) {
cout << "NO" << endl;
}
else {
int p = abs(y2 - y11) / y;
int pp = abs(x2 - x1) / x;
if (abs(x2-x1)%x) cout<<"NO\n";
else if (abs(p - pp) & 1) cout << "NO\n";
else if ((abs(p-pp)&1)==0) cout << "YES\n";
}
return 0;
}
B - Makes And The Product
题目链接https://codeforces.com/problemset/problem/817/B
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false)
#define ok(x) (x>0 && x<150000)
#define ll long long
const int mac = 2e5 + 10;
const int inf = 1e8 + 10;
int a[mac], vis[mac];
int main()
{
IOS;
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + 1 + n);
int x1 = inf, x2 = inf, x3 = inf;
x1 = a[1]; x2 = a[2]; x3 = a[3];
ll nb1=0, nb2=0, nb3=0;
for (int i = 1; i <= n; i++) {
if (a[i] == x1) nb1++;
else if (a[i] == x2) nb2++;
else if (a[i] == x3) nb3++;
}
//ll p1 = nb1, p2 = nb2 - nb1, p3 = nb3 - nb2;
if (x1 != x2 && x2 != x3 && x1 != x3) {
cout << nb1 * nb2 * nb3 << endl;
}
else if (x1 == x2 && x1 != x3) {
cout << nb3 << endl;
}
else if (x2 == x3 && x1 != x2) cout << nb2 * (nb2 - 1) / 2 << endl;
else if (x1 == x2 && x2 == x3) {
cout << nb1 * (nb1 - 1) * (nb1 - 2) / 6 << endl;
}
return 0;
}
C - Really Big Numbers
题目链接https://codeforces.com/problemset/problem/817/C
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false)
#define ll long long
const int mac = 2e5 + 10;
const int inf = 1e8 + 10;
int a[mac], vis[mac], b[mac];
ll s, n;
int ok(ll x);
int main()
{
IOS;
cin >> n >> s;
ll l = 10, r = n, mid, ans=-1;
while (l <= r) {
mid = (l + r) >> 1;
if (ok(mid)) {
r = mid - 1;
ans = mid;
}
else l = mid + 1;
}
if (ans == -1) cout << 0 << endl;
else cout << n - ans + 1;
return 0;
}
int ok(ll x)
{
ll p = x, sum = 0;
while (p) {
sum += p % 10;
p /= 10;
}
if (x - sum >= s) return 1;
return 0;
}
D - Diplomas and Certificates
题目链接https://codeforces.com/problemset/problem/818/A
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false)
#define ok(x) (x>0 && x<150000)
#define ll long long
const int mac = 2e5 + 10;
const int inf = 1e8 + 10;
int a[mac], vis[mac];
int main()
{
IOS;
ll n, k;
cin >> n >> k;
ll p = n / 2;
ll u = p / (k + 1);
if (u==0) cout<<"0 0 "<<n<<endl;
else cout << u << " " << k*u << " " << n - u-k*u<< endl;
return 0;
}
E - Permutation Game
题目链接https://codeforces.com/problemset/problem/818/B
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false)
#define ok(x) (x>0 && x<150000)
#define ll long long
const int mac = 2e5 + 10;
const int inf = 1e8 + 10;
int a[mac], vis[mac], b[mac],v[mac];
int main()
{
IOS;
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++)
cin >> a[i];
int mod = n;
for (int i = 1; i <= m - 1; i++) {
if (vis[b[a[i]]]) {
int p = (a[i + 1] - a[i] + mod) % mod;
if (!p) p = n;
if (p != b[a[i]]) { cout << -1 << endl; return 0; }
}
else b[a[i]] = (a[i + 1] - a[i] + mod) % mod;
if (b[a[i]] == 0) b[a[i]] = n;
vis[b[a[i]]] = 1;
}
for (int i = 1; i <= n; i++) {
if (!b[i]) {
for (int j=1; j<=n; j++)
if (!vis[j]) { b[i] = j; vis[j] = 1; break; }
}
}
for(int i=1; i<=n; i++){
if (!v[b[i]]) v[b[i]]=1;
else {
cout<<-1<<endl;return 0;
}
}
for (int i = 1; i < n; i++) cout << b[i] << " ";
cout << b[n] << endl;
return 0;
}