Odpowiedź:
#include <iostream>
#include <vector>
int main() {
int n, q;
std::cin >> n >> q;
std::vector<int> lengths(n);
for (int i = 0; i < n; i++) {
std::cin >> lengths[i];
}
std::vector<int> cumulativeLengths(n);
cumulativeLengths[0] = lengths[0];
for (int i = 1; i < n; i++) {
cumulativeLengths[i] = cumulativeLengths[i - 1] + lengths[i];
for (int i = 0; i < q; i++) {
int x, y;
std::cin >> x >> y;
int monsterPosition = cumulativeLengths[x - 1];
int playerPosition = cumulativeLengths[y - 1];
double monsterTime = static_cast<double>(monsterPosition) / 20.0;
double playerTime = static_cast<double>(playerPosition) / 10.0;
if (playerTime < monsterTime) {
std::cout << "TAK" << std::endl;
} else {
std::cout << "NIE" << std::endl;
return 0;
Wyjaśnienie:
" Life is not a problem to be solved but a reality to be experienced! "
© Copyright 2013 - 2024 KUDO.TIPS - All rights reserved.
Odpowiedź:
#include <iostream>
#include <vector>
int main() {
int n, q;
std::cin >> n >> q;
std::vector<int> lengths(n);
for (int i = 0; i < n; i++) {
std::cin >> lengths[i];
}
std::vector<int> cumulativeLengths(n);
cumulativeLengths[0] = lengths[0];
for (int i = 1; i < n; i++) {
cumulativeLengths[i] = cumulativeLengths[i - 1] + lengths[i];
}
for (int i = 0; i < q; i++) {
int x, y;
std::cin >> x >> y;
int monsterPosition = cumulativeLengths[x - 1];
int playerPosition = cumulativeLengths[y - 1];
double monsterTime = static_cast<double>(monsterPosition) / 20.0;
double playerTime = static_cast<double>(playerPosition) / 10.0;
if (playerTime < monsterTime) {
std::cout << "TAK" << std::endl;
} else {
std::cout << "NIE" << std::endl;
}
}
return 0;
}
Wyjaśnienie: