A. Sasha and the Beautiful Array
题意:计算a(i+1)-a(i)的最大值。
思路:只要计算最大值减最小值。
#include<bits/stdc++.h>
#define Max 0x7fffffff
#define LL long long
#define ULL unsigned long long
#define N 1000005
#define int long long
#define mod 1000000007
using namespace std;
signed main() {
int T; scanf("%lld", &T);
while (T--) {int maxx = 0, minn = Max;
int n; scanf("%lld", &n);
while (n--) {
int t; scanf("%lld", &t);
maxx = max(maxx, t);
minn = min(minn, t);
}
printf("%lld\n", maxx - minn);
}
}
B. Sasha and the Drawing
题意:有n*n个格子,(4*n-2)条对角线,要求有k条对角线,每条对角线上至少有一个格子需要涂色。
思路: 每个格子都有两条对角线穿过,但主对角线和副对角线会穿过两个格子,也就是这两个格子只能提供3条对角线。
#include<bits/stdc++.h>
#define Max 0x7fffffff
#define LL long long
#define ULL unsigned long long
#define N 1000005
#define int long long
#define mod 1000000007
using namespace std;
signed main() {
int T; scanf("%lld", &T);
while (T--) {int maxx = 0, minn = Max;
int n,k; scanf("%lld%lld", &n,&k);
if (k <= 4 * n - 4)printf("%lld\n", (k + 1) / 2);
else if (k == 4 * n - 3)printf("%lld\n", n * 2 - 1);
else {
printf("%lld\n", n * 2);
}
}
}
C. Sasha and the Casino
题意:
思路:倍投法,保证如果赢一次总收益为正,因为有保底所以可以要保证他的硬币数足以撑到x+1回合,假设已经投入sum,那么每次的投入now就需要满足k*now>sum+now;now=sum/(k-1)+1;
#include<bits/stdc++.h>
#define Max 0x7fffffff
#define LL long long
#define ULL unsigned long long
#define N 1000005
#define int long long
#define mod 1000000007
using namespace std;
signed main() {
int T; scanf("%lld", &T);
while (T--) {
int k, x, a; scanf("%lld%lld%lld", &k, &x, &a);
LL now = 0,sum=0,fl=1;
for (int i = 0; i <= x; i++) {
now = sum/(k - 1)+1;
sum += now;
if (sum > a) {
fl = 0; break;
}
}
printf("%s\n", fl ? "yes" : "no");
}
}