A
.
P
i
z
z
a
F
o
r
c
e
s
A. PizzaForces
A.PizzaForces
水题,分奇偶两种情况讨论,如果是偶数的话直接/2*5,如果是奇数的话就+1再/2*5。
#include<bits/stdc++.h>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
#define int long long
#define IO ios::sync_with_stdio(false);\
cin.tie(NULL);\
cout.tie(NULL);
#define MULTICASE int _;cin >> _;while(_ --)
#pragma GCC optimize(2)
void solve()
{
int n;
cin >> n;
if(n < 6)
{
cout << 15 << '\n';
return ;
}
if(n & 1)
{
cout << (n + 1) / 2 * 5 << '\n';
}
else
{
cout << n / 2 * 5 << '\n';
}
}
signed main(){
IO
MULTICASE
solve();
}
B
.
T
w
o
T
a
b
l
e
s
B. Two Tables
B.TwoTables
分情况讨论即可。
#include<bits/stdc++.h>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
#define int long long
#define IO ios::sync_with_stdio(false);\
cin.tie(NULL);\
cout.tie(NULL);
#define MULTICASE int _;cin >> _;while(_ --)
#pragma GCC optimize(2)
#define NO cout << "-1" << '\n';
void solve()
{
double W, H, w, h, x1, x2, y1, y2;
scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &W, &H, &x1, &y1, &x2, &y2, &w, &h);
double ans = 1e9;
double w1 = x2 - x1, h1 = y2 - y1;
if(w1 + w > W && h1 + h > H)
{
NO
return ;
}
if(w1 + w <= W)
{
if(x2 + w <= W || w <= x1)
{
printf("0.000000000\n");
return ;
}
ans = min({ans, w - (W - x2), w - x1});
}
if(h1 + h <= H)
{
if(y2 + h <= H || y1 >= h)
{
printf("0.000000000\n");
return ;
}
ans = min({ans, h - y1, h - (H - y2)});
}
printf("%.9lf\n", ans);
return ;
}
signed main(){
MULTICASE
solve();
}
C
.
C
o
i
n
R
o
w
s
C. Coin Rows
C.CoinRows
观察Alice的路线,我们可以看出Bob只能取到第一行的一个后缀或者第二行的一个前缀的硬币总和,枚举Alice向下走的位置,取出后缀和前缀的最大值,由此编程。
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IO ios::sync_with_stdio(false);\
cin.tie(NULL);\
cout.tie(NULL);
#define MULTICASE int _;cin >> _;while(_ --)
#pragma GCC optimize(2)
#define NO cout << "-1" << '\n';
const int N = 200000 + 200;
void readarray(int *a, int n)
{
for(int i = 1; i <= n; i ++)
cin >> a[i];
}
int a[2][N];
int prefix[N], suffix[N];
void solve()
{
int n;
cin >> n;
readarray(a[0], n);
readarray(a[1], n);
prefix[0] = 0, suffix[n + 1] = 0;
for(int i = 1; i <= n; i ++)
{
prefix[i] = prefix[i - 1] + a[1][i];
suffix[n - i + 1] = suffix[n - i + 2] + a[0][n - i + 1];
}
int ret = 1e18;
for(int i = 1; i <= n; i ++)
{
int ans = max(prefix[i - 1], suffix[i + 1]);
ret = min(ret, ans);
}
cout << ret << '\n';
}
signed main(){
IO
MULTICASE
solve();
}
D
.
S
a
y
N
o
t
o
P
a
l
i
n
d
r
o
m
e
s
D. Say No to Palindromes
D.SayNotoPalindromes
令
S
S
S为
{
A
,
B
,
C
}
\{A,B,C\}
{A,B,C}的一个排列,我们只需要构造
S
n
S^n
Sn即可使得这个字符串没有长度大于1的回文串。
像是
A
B
C
A
B
C
A
B
.
.
.
∣
B
A
C
B
A
C
B
A
C
B
.
.
.
ABCABCAB...|BACBACBACB...
ABCABCAB...∣BACBACBACB...
就不含有长度大于1的字符串。
了解这一点后,我们可以做出这道题。
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IO ios::sync_with_stdio(false);\
cin.tie(NULL);\
cout.tie(NULL);
#define MULTICASE int _;cin >> _;while(_ --)
#pragma GCC optimize(2)
#define NO cout << "-1" << '\n';
const int N = 200000 + 200;
int a[6][N];
char t[N];
int b[4] = {0, 0, 1, 2};
void solve()
{
int n, m;
cin >> n >> m;
cin >> t + 1;
int len = strlen(t + 1), tot = 0;
do
{
int j = 1;
for(int i = 1; i <= len; i ++)
{
a[tot][i] = a[tot][i - 1] + (t[i] != ('a' + b[j]));
j = j % 3 + 1;
}
tot ++;
}while(next_permutation(b + 1, b + 4));
for(int i = 1; i <= m; i ++)
{
int l, r;
cin >> l >> r;
int mi = 1e9;
for(int j = 0; j < 6; j ++)
{
mi = min(mi, a[j][r] - a[j][l - 1]);
}
cout << mi << '\n';
}
}
main(){
IO
solve();
}