好气人,今天刷cf的时候被C. Ball in Berland这道题搞得心态爆炸
A. Alexey and Train
小模拟,算火车最后什么时候到终点,火车在每站的出发时间有两种情况。第一种就是题目给的数据,第二种就是火车实际到达的时间加上停止的时间,两者取一个最大值即是出发时间。
处理下每次到站所需的时间,b[i + 1] - a[i] 再加上迟到的时间。注意最后输出的是到达的时间,所以不需要加上等候的时间,加个特判。
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
long long a[N], b[N], t[N], tim[N];
int T, n;
int main()
{
cin >> T;
while (T -- )
{
cin >> n;
for (int i = 1; i <= n; i ++ )
{
scanf("%d", &a[i]);
scanf("%d", &b[i]);
}
b[0] = 0, a[0] = 0;
for (int i = 1; i <= n; i ++ ) scanf("%d", &t[i]);
for (int i = 0; i <= n - 1; i ++ )
tim[i + 1] = a[i + 1] - b[i] + t[i + 1];
//计算时间
long long star = 0;
for (int i = 1; i <= n; i ++ )
{
long long sta = ceil((b[i] - a[i]) * 1.0 / 2);
if (i != n)
{
star += tim[i] + sta;
star = max(star, b[i]);
}
if (i == n) star += tim[i];
}
cout << star << endl;
}
return 0;
}
B. Napoleon Cake
题意:放次蛋糕,倒次奶油,最后从底部打印出被奶油覆盖的蛋糕。
如果一个处在i位置的蛋糕要被奶油覆盖到,需要奶油从j > i 的位置倒下来,且a[j] - j < i,从顶部往下枚举,每次更新奶油覆盖到的最下面的位置,并判断当前层的蛋糕能否被覆盖。
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int a[N], vis[N];
int t, n;
int main()
{
scanf("%d", &t);
while (t -- )
{
scanf("%d", &n);
memset(vis, 0, sizeof(vis));
for (int i = 1; i <= n; i ++ ) scanf("%d", &a[i]);
int ans = 200010;
for (int i = n; i >= 1; i -- )
{
ans = min(ans, i - a[i]);
if (ans < i) vis[i] = 1;
}
for (int i = 1; i <= n; i ++ ) printf("%d ", vis[i]);
puts("");
}
return 0;
}
C. Going Home
就暴力,什么鬼
已知a[i] + a[j] <= 5e6,每队i,j都对应一个不同的值,当我们枚举5e6 + 1个i, j 时,根据鸽巢原理,一定有对i, j相等,所以暴力可以。
#include <bits/stdc++.h>
using namespace std;
const int N = 5000010;
int a[N], b[N], c[N];
int n;
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i ++ ) scanf("%d", &a[i]);
for (int i = 1; i <= n; i ++ )
for (int j = i + 1; j <= n; j ++ )
{
int ans = a[i] + a[j];
if (!b[ans])
{
b[ans] = i;
c[ans] = j;
}
else
{
if (b[ans] != i && b[ans] != j && c[ans] != i && c[ans] != j)
{
puts("YES");
printf("%d %d %d %d\n", i, j, b[ans], c[ans]);
return 0;
}
}
}
puts("NO");
return 0;
}