CC BY 4.0 (除特别声明或转载文章外)
如果这篇博客帮助到你,可以请我喝一杯咖啡~
Is It Easy ?
1
2
3
#include <stdio.h>
int n, k;
int main() { scanf("%d%d", &n, &k), printf("%d", n * k); }
Road to Arabella
1
2
3
4
5
6
7
#include <stdio.h>
int t, n, k;
int main()
{
for (scanf("%d", &t); t--; printf(n > k + 1 || n % 2 ? "Kilani\n" : "Ayoub\n"))
scanf("%d%d", &n, &k);
}
Check The Text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <bits/stdc++.h>
using namespace std;
const int N = 8e6 + 9;
int n, L, k;
char s[N], st[N], ne[N], op[N];
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
scanf("%s", &s);
int Len = strlen(s);
for (int j = 0; j < Len; j++)
st[++L] = s[j];
st[++L] = ' ';
}
L--;
scanf("%d", &k);
int now = 0, tp = 0;
for (int i = 1; i <= k; i++)
{
scanf("%s", &op);
if (op[0] == 'C')
tp = (tp + 1) % 2;
else if (op[0] == 'B')
{
if (now > 0)
now--;
}
else if (op[0] == 'S')
ne[++now] = ' ';
else if (tp == 0)
ne[++now] = op[0];
else
ne[++now] = op[0] - 32;
}
bool ok = true;
if (now != L)
ok = false;
for (int i = 1; i <= L; i++)
if (ne[i] != st[i])
ok = false;
printf(ok ? "Correct\n" : "Incorrect\n");
}
Meeting Bahosain
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 9;
ll d, a[N], b[N];
int n, m;
int main()
{
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i)
scanf("%I64d", &a[i]);
for (int i = 0; i < m; ++i)
scanf("%I64d", &b[i]);
if (m == 1)
d = b[0];
else
{
d = __gcd(b[0], b[1]);
for (int i = 2; i < m; ++i)
d = __gcd(d, b[i]);
}
for (int i = 1; i < n; ++i)
if (abs(a[i] - a[0]) % d)
return printf("NO"), 0;
printf("Yes");
}
Longest path Problem
1
//待补
Musical Chairs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <bits/stdc++.h>
using namespace std;
const int N = 1023;
int n, p;
int len[N];
int eli[N];
int cor[N];
long long num, nex;
bool f[N][N];
int main()
{
scanf("%d%d", &n, &p);
for (int i = 1; i < n; ++i)
scanf("%d", &len[i]);
for (int i = 1; i < n; ++i)
scanf("%d", &eli[i]);
for (int i = 1; i <= n; ++i)
cor[i] = i;
f[0][p] = 1;
num = n;
for (int i = 1, beg; i < n; ++i, --num)
{
for (int j = 1; j <= num; ++j)
{
if (f[i - 1][cor[j]])
{
nex = j + len[i];
nex = (nex - 1) % num + 1;
nex = cor[nex];
if (nex != eli[i])
f[i][nex] = 1;
nex = j - len[i];
nex = ((nex - 1) % num + num) % num + 1;
nex = cor[nex];
if (nex != eli[i])
f[i][nex] = 1;
}
if (cor[j] == eli[i])
beg = j;
}
for (int j = beg; j < num; ++j)
swap(cor[j], cor[j + 1]);
}
printf(f[n - 1][cor[1]] ? "Yes" : "No");
}
Card Game
1
2
3
4
5
6
7
8
9
10
#include <stdio.h>
double ans;
int n;
int main()
{
scanf("%d", &n);
for (int i = 1; i < n; ++i)
ans += 1.0 * i * (i + 1);
printf("%.7f\n", ans / n);
}
Steaks
1
2
3
4
5
6
7
8
9
10
11
#include <bits/stdc++.h>
using namespace std;
long long n, k;
int main()
{
cin >> n >> k;
if (k * 2 >= n)
cout << 10;
else
cout << ((n * 2) / (k * 2) + (((n * 2) % (k * 2)) ? 1 : 0)) * 5;
}
https://vjudge.net/problem/Gym-102263I
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 9;
deque<ll> q;
int n;
int main()
{
scanf("%d", &n);
for (int i = 0, t; i < n; ++i)
{
scanf("%d", &t);
q.push_back(t);
}
sort(q.begin(), q.end());
ll presum = q.front(), sufsum = q.back(), precnt = 1, sufcnt = 1, ans = sufsum - presum;
q.pop_front(), q.pop_back();
for (int i = 2; i < n; ++i)
{
cout << ans << ' ';
if (i & 1)
{
ll t = q.front();
q.pop_front();
ans += t * precnt - presum + sufsum - t * sufcnt;
++precnt, presum += t;
}
else
{
ll t = q.back();
q.pop_back();
ans += t * precnt - presum + sufsum - t * sufcnt;
++sufcnt, sufsum += t;
}
}
cout << ans;
}
Thanos Power
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
string st;
long long f[N], g[N];
int n;
int main()
{
cin >> st;
n = st.size();
f[0] = st[0] - '0';
g[0] = 2 + 9 - (st[0] - '0');
for (int i = 1; i < n; ++i)
{
f[i] = min(f[i - 1], g[i - 1]) + (st[i] - '0');
g[i] = min(f[i - 1] + 2 + 9 - (st[i] - '0'), g[i - 1] + 9 - (st[i] - '0'));
}
cout << min(f[n - 1], g[n - 1]);
}
Smart Strategies
1
//待补
Burgers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M = 1e9 + 7;
ll cal(ll n, ll r)
{
ll g = __gcd(n, r);
if (g == 1)
return (1 + n) * n / 2 % M;
return cal(n / g, r / g) * g % M;
}
int main()
{
int n, m, r, c;
scanf("%d%d%d%d", &n, &m, &r, &c);
ll k = n / __gcd(n, r), t = m / __gcd(m, c), g = __gcd(k, t);
cout << (t / g * cal(n, r) % M * m % M + k / g * cal(m, c) % M + M - k / g * t % M * m % M) % M;
}
Two Operations
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 9;
char s[N];
int a[31];
int main()
{
scanf("%s", &s);
for (int i = 0; s[i]; ++i)
++a[s[i] - 'a'];
for (int i = 1; i < 26; ++i)
a[i] += a[i - 1] >> 1, a[i - 1] &= 1;
for (char c = 'z'; c >= 'a'; --c)
cout << string(a[c - 'a'], c);
}