A - Berland Poker[思维]
B - New Theatre Square[思维]
C - Mixing Water[数学]
D - Yet Another Yet Another Task[枚举][区间最大值]
E - Modular Stability[组合数][思维]
F - RC Kaboom Show[几何]
A - Berland Poker[思维]
Time Limit Per Test | Memory Limit Per Test | input | output |
---|---|---|---|
2 seconds | 256 megabytes | standard input | standard output |
题意
n n n 张扑克牌, m m m 张是开玩笑, k k k 个玩家
玩家间的得分为手上为开玩笑扑克牌的个数
两两玩家之间的牌数量最多只能相差一张
问 两玩家的得分差值最小 的最大值为多少
做法
将开玩笑牌分配给第一个人,分配完后再将剩余的开玩笑牌平均分配给剩余的 k − 1 k - 1 k−1 个人
样例
输入
4
8 3 2
4 2 4
9 6 3
42 0 7
输出
3
0
1
0
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define min(a,b) ((a)>(b)?(b):(a))
#define max(a,b) ((a)>(b)?(a):(b))
const int inf = 0x3f3f3f3f;
const int maxm = 1e5 + 5;
const int maxn = 5e3 + 5;
int main() {
int T;
scanf("%d", &T);
while(T--) {
scanf("%d%d%d", &n, &m, &k);
int x = min(n / k, m);
int y = m - x;
if(y % (k - 1))
y = y / (k - 1) + 1;
else
y /= (k - 1);
printf("%d\n", x - y);
}
return 0;
}
B - New Theatre Square[思维]
Time Limit Per Test | Memory Limit Per Test | input | output |
---|---|---|---|
2 seconds | 256 megabytes | standard input | standard output |
题意
给一个 n × m n \times m n×m 的图, ′ . ′ '.' ′.′ 为白色块, ′ ∗ ′ '*' ′∗′ 为黑色块
每个 1 × 1 1 \times 1 1×1 的砖块花费为 x x x, 1 × 2 1 \times 2 1×2 的砖块花费为 y y y,砖块不能翻转或切割
要将所有的白色块填满,不能填到黑色块,最少的花费为多少
做法
令 y = m i n ( 2 ∗ x , y ) y = min(2 * x, y) y=min(2∗x,y), 1 × 2 1 \times 2 1×2 的块可以由两个 1 × 1 1 \times 1 1×1 的块拼起来
之后暴力遍历图
样例
输入
4
1 1 10 1
.
1 2 10 1
..
2 1 10 1
.
.
3 3 3 7
..*
*..
.*.
输出
10
1
20
18
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define min(a,b) ((a)>(b)?(b):(a))
#define max(a,b) ((a)>(b)?(a):(b))
const int inf = 0x3f3f3f3f;
const int maxm = 1e5 + 5;
const int maxn = 100 + 5;
char s[maxn];
int main() {
int T;
scanf("%d", &T);
while(T--) {
int n, m, x, y; ll ans = 0;
scanf("%d%d%d%d", &n, &m, &x, &y);
y = min(y, x * 2);
for(int i = 1; i <= n; ++i) {
scanf("%s", s + 1);
for(int j = 1; j <= m; ++j) {
if(s[j] == '.' && s[j + 1] == '.')
ans += y * 1ll, j += 1;
else if(s[j] == '.')
ans += x * 1ll;
}
}
printf("%lld\n", ans);
}
return 0;
}
C - Mixing Water[数学]
Time Limit Per Test | Memory Limit Per Test | input | output |
---|---|---|---|
2 seconds | 256 megabytes | standard input | standard output |
题意
热水的温度为 h h h,冷水的温度为 c c c,目标温度为 t t t
桶内温度为所有倒入的水的温度平均值
倒入水的顺序为 热水、冷水、热水、冷水、热水 . . . ... ...
问要得到最接近 t t t 的温度,至少要倒多少杯水
做法
可以发现倒入偶数杯水的时候,温度必然变为 ( h + c ) / 2 (h + c) / 2 (h+c)/2
当 h = = t h == t h==t 的时候,只要倒入一杯热水
当 2 ∗ t ≤ h + c 2 * t \leq h + c 2∗t≤h+c 的时候,倒入两杯水就是最接近的
否则,只要找到最近接的情况应该是为 n + 1 n + 1 n+1 或者 n + 2 n +2 n+2 杯热水的情况
每当(最初里面有一杯热水)多增加一杯热水和冷水时,总体温度呈下降趋势
假设为 n + 1 n + 1 n+1 杯热水的情况
( n + 1 ) ∗ h + n c 2 n + 1 ≤ t → n ≤ ( 2 n + 1 ) ( t − h ) / ( c + h ) \frac{(n + 1) * h + nc}{2n + 1} \leq t \rightarrow n \leq (2n+1)(t-h) / (c+h) 2n+1(n+1)∗h+nc≤t→n≤(2n+1)(t−h)/(c+h)
再多计算一个 n + 1 n + 1 n+1 时的温度,比较差值大小
样例1
输入
3
30 10 20
41 15 30
18 13 18
输出
2
7
1
代码
#include <bits/stdc++.h>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1e3 + 5;
int main() {
int T;
scanf("%d", &T);
while(T--) {
ll t, c, h;
scanf("%lld%lld%lld", &h, &c, &t);
if(h == t) puts("1");
else if(h + c >= 2 * t) puts("2");
else{
double t1, t2;
ll n1 = (t - h) / (h + c - 2 * t), n2 = n1 + 1;
// printf("%d %d\n", n1, n2);
t1 = ((n1 + 1) * h + n1 * c) * 1.0 / (2.0 * n1 + 1.0);
t2 = ((n2 + 1) * h + n2 * c) * 1.0 / (2.0 * n2 + 1.0);
printf("%lld\n", (fabs(t1 - t) > fabs(t2 - t) ? n2 : n1) * 2 + 1ll);
}
}
return 0;
}
F - RC Kaboom Show[几何]
Time Limit Per Test | Memory Limit Per Test | input | output |
---|---|---|---|
2 seconds | 512 megabytes | standard input | standard output |
题意
每个车有一个坐标 ( x , y ) (x, y) (x,y),方向为向量 ( d x , d y ) (dx, dy) (dx,dy),速度为 s s s
求有两辆车相撞的最短时间
做法
大概是几何+数学+暴力把
我的脑子已经不想在思考了
麻烦走一下传送门
F. RC Kaboom Show 2900分计算几何之大力出奇迹