A - Jogging
Takahashi and Aoki decided to jog.
Takahashi repeats the following: “walk at Bmeters a second for Aseconds and take a rest for Cseconds.”
Aoki repeats the following: “walk at Emeters a second for Dseconds and take a rest for Fseconds.”
When Xseconds have passed since they simultaneously started to jog, which of Takahashi and Aoki goes ahead?
Input is given from Standard Input in the following format:
A B C D E F X
When XX seconds have passed since they simultaneously started to jog, if Takahashi goes ahead of Aoki, print Takahashi
; if Aoki goes ahead of Takahashi, print Aoki
; if they have advanced the same distance, print Draw
.
4 3 3 6 2 5 10
Takahashi
During the first 10 seconds after they started to jog, they move as follows.
Since Takahashi goes ahead, Takahashi
should be printed.
这道题不难,不过相对以往比赛第一题,稍有难度。
我在线上参加比赛时编写的代码如下,是不是写的比较绕了。
主要是当时心态有些急,如果稍加分析,理清思路,很快就能秒掉该题。
void coder_solution() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int a, b, c, d, e, f, x, g, h;
cin >> a >> b >> c >> d >> e >> f >> x;
if (x <= a + c) {
if (x >= a && x <= a + c) {
g = a * b;
} else {
g = x * b;
}
}
if (x <= d + f) {
if (x >= d && x <= d + f) {
h = d * e;
} else {
h = x * e;
}
}
if (x > a + c) {
g = x / ( a + c) * a * b;
if (x % ( a + c) >= a) {
g += a * b;
} else {
g += x % ( a + c) * b;
}
}
if (x > d + f) {
h = x / ( d + f) * d * e;
if (x % ( d + f) > d) {
h += d * e;
} else {
h += x % (d + f) * e;
}
}
if ( g > h) {
cout << "Takahashi";
} else if ( g == h) {
cout << "Draw";
} else {
cout << "Aoki";
}
}
void best_solution() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int a, b, c, d, e, f, x;
cin >> a >> b >> c >> d >> e >> f >> x;
int takahashi = 0, aoki = 0;
for (int k = 0; k < x; ++k) {
if (k % (a + c) < a) {
takahashi += b;
}
if (k % (d + f) < d) {
aoki += e;
}
}
if (takahashi > aoki) {
cout << "Takahashi\n";
} else if (takahashi < aoki) {
cout << "Aoki\n";
} else {
cout << "Draw\n";
}
}
这个是今天晚上做复盘时,重写的代码,比之前线上比赛时简洁多了。
主要是还学习到了新知识。(呵呵…)
void best_solution() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// 输入
int a, b, c, d, e, f, x;
cin >> a >> b >> c >> d >> e >> f >> x;
// 定义函数
auto calc = [&](int a, int b, int c, int x) {
int m = x / (a + c) * a * b;
if (x % (a + c) >= a) {
m += a * b;
} else {
m += x % (a + c) * b;
}
return m;
};
// 分别计算
int takahashi = calc(a, b, c, x);
int aoki = calc(d, e, f, x);
// 输出
if (takahashi > aoki) {
cout << "Takahashi";
} else if (takahashi < aoki) {
cout << "Aoki";
} else {
cout << "Draw";
}
}