首先说一下这场特别热血。
开局不利,脑抽了一下错了两发,然后B题是O(n^2)不知道为啥不是TLE,死活de不出来。本来以为是要掉分了。
最后抱着试一试的心理开了C题,感觉思路没什么问题,但是wa了,大概是最后6、7分钟推倒重写了,在最后的1分钟交上了,完成了绝杀啊哈哈哈,超级热血。
感觉这也是打cf的乐趣之一了。
A题
这题就是如果一个数可以被后面的数减为0的话,那么这个数一定是后面那个数的整数倍,那么这样递推下去的话,每个数都是第一个数的整数倍,判断一下即可。
// Problem: A. Difference Operations
// Contest: Codeforces - Codeforces Round #808 (Div. 2)
// URL: https://codeforces.com/contest/1708/problem/0
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
while (b)
{
int temp = b;
b = a % b;
a = temp;
}
return a;
}
int a[105];
int main()
{
int t;
cin >> t;
while (t--)
{
memset(a, 0, sizeof(a));
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
int flag = 1;
for (int i = 1; i <= n - 1; i++)
{
if (a[i + 1] % a[1] != 0)
{
flag = 0;
break;
}
}
if (flag)
{
printf("YES\n");
}
else
puts("NO");
}
}
B
这题就是构造一个数组,其实不用那么老实,按照题目的要求求gcd,我们可以倒推,就是在给定的区间里面查找整数倍,那么显然题目要求的i应该是从1到n,这样可以使用最小的区间满足题目的需要。所以我们只需要把i从1遍历到n,然后查找区间内有没有整数倍就可以了。
查找区间内是否存在这个整数倍的数的方式是判断((l - 1) / i + 1) * i是否小于r,因为(l-1)/ i 会自动向下取整,那么(l-1)/ i 算出来的就是最接近 l-1 的i的整数倍,所以((l - 1) / i + 1) * i 一定是大于l的,只要判断是否小于r即可。
// Problem: B. Difference of GCDs
// Contest: Codeforces - Codeforces Round #808 (Div. 2)
// URL: https://codeforces.com/contest/1708/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N];
int b[N];
int gcd(int a, int b)
{
while (b)
{
int temp = b;
b = a % b;
a = temp;
}
return a;
}
int main()
{
int t;
cin >> t;
while (t--)
{
memset(a, 0, sizeof(a));
int n;
int l, r;
cin >> n;
cin >> l >> r;
int flag = 1;
for (int i = 1; i <= n; i++)
{
int temp = ((l - 1) / i + 1) * i;
if (temp <= r)
a[i] = temp;
else
flag = 0;
}
if (flag == 1)
{
puts("YES");
for (int i = 1; i <= n; i++)
{
if (i == n)
printf("%d\n", a[i]);
else
printf("%d ", a[i]);
}
}
else
puts("NO");
}
}
C
这题就是贪心了,我们知道q的值越大肯定是越好的,所以要强行参加的比赛要尽量放在后面,那么就可以分为两段了,一段是不消耗q去参赛,还有一段是消耗q来参赛,我们可以模拟一个逆过程,即是定义一个临时变量x,然后倒着遍历数组,当x<q的时候,这一段一定是都可以参加的,当当前的ai>x的时候就x++,当x=q的时候,说明消耗q的这一段结束了,前面的就是不消耗q来参赛了。
// Problem: C. Doremy's IQ
// Contest: Codeforces - Codeforces Round #808 (Div. 2)
// URL: https://codeforces.com/contest/1708/problem/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N];
int b[N];
int c[N];
int main()
{
int t;
cin >> t;
while (t--)
{
int n, q;
cin >> n >> q;
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(c, 0, sizeof(c));
int ans = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
if (a[i] > q)
{
b[++ans] = i;
}
}
int cnt = 0;
int temp = q;
for (int i = n; i >= 1; i--)
{
if (cnt < q)
{
if (a[i] > cnt)
cnt++;
c[i] = 1;
}
else
{
if (q >= a[i])
c[i] = 1;
else
{
c[i] = 0;
}
}
}
for (int i = 1; i <= n; i++)
{
if (i == n)
printf("%d\n", c[i]);
else
printf("%d", c[i]);
}
}
}