这道题非常的简单,只要你学了C++就可以做出来
这道题建议降红
代码:
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
struct SegmentData {
string type;
double speedLimit;
double actualSpeed;
double tiltAngle;
double signalDistance;
int doorDirRequired;
int doorDirActual;
int doorOpenTime;
int scheduledArrival;
int actualArrival;
int alignRange;
int alignDistance;
bool derailed;
int segmentNum;
};
struct Node {
SegmentData data;
Node* left;
Node* right;
int score;
Node(SegmentData d) : data(d), left(nullptr), right(nullptr), score(0) {}
};
class ScoreTree {
private:
Node* root;
int totalScore;
bool hasDerailed;
double maxDesignSpeed;
double maxTiltAngle;
void insert(Node*& node, SegmentData data) {
if (!node) {
node = new Node(data);
calculateScore(node);
totalScore += node->score;
return;
}
if (data.segmentNum < node->data.segmentNum)
insert(node->left, data);
else
insert(node->right, data);
}
void calculateScore(Node* node) {
SegmentData& d = node->data;
int score = 0;
if (d.derailed && !hasDerailed) {
score -= 100;
hasDerailed = true;
}
if (d.signalDistance > 0)
score -= static_cast<int>(ceil(d.signalDistance)) * 10;
if (d.actualSpeed > d.speedLimit) {
double over = d.actualSpeed - d.speedLimit;
score -= static_cast<int>(ceil(over)) * 10;
}
if (d.actualSpeed > maxDesignSpeed) {
double over = d.actualSpeed - maxDesignSpeed;
score -= static_cast<int>(ceil(over)) * 10;
}
if (d.type == "Round" && d.actualSpeed > d.speedLimit) {
double over = d.actualSpeed - d.speedLimit;
score -= static_cast<int>(ceil(over)) * 10;
}
if (d.tiltAngle > maxTiltAngle) {
double over = d.tiltAngle - maxTiltAngle;
score -= static_cast<int>(ceil(over)) * 10;
}
if (d.type == "Station") {
if (abs(d.alignDistance) > d.alignRange)
score -= 15;
else if (abs(d.alignDistance) <= d.alignRange * 0.1)
score += 15;
int diff = d.actualArrival - d.scheduledArrival;
if (abs(diff) > 5) {
int over = abs(diff) - 5;
score -= over * 20;
}
if (d.doorDirActual != 0 && d.doorDirActual != d.doorDirRequired)
score -= d.doorOpenTime * 10;
} else {
if (d.doorDirActual != 0)
score -= d.doorOpenTime * 10;
}
node->score = score;
}
void inOrder(Node* node) {
if (!node) return;
inOrder(node->left);
cout << node->data.segmentNum << " " << node->data.type << " " << node->score << endl;
inOrder(node->right);
}
public:
ScoreTree(double x, double y) : root(nullptr), totalScore(100), hasDerailed(false), maxDesignSpeed(x), maxTiltAngle(y) {}
void addSegment(SegmentData data) {
insert(root, data);
}
void printResults() {
inOrder(root);
string penalty;
if (totalScore < -150) penalty = "Out";
else if (totalScore < -100) penalty = "SeriouslyWarn";
else if (totalScore < -50) penalty = "Warn";
else penalty = "None";
cout << totalScore << " " << penalty << endl;
}
};
int main() {
int n;
cin >> n;
double x, y;
cin >> x >> y;
ScoreTree tree(x, y);
for (int i = 0; i < n; ++i) {
SegmentData d;
d.segmentNum = i + 1;
cin >> d.type;
cin >> d.speedLimit;
cin >> d.actualSpeed;
cin >> d.tiltAngle;
cin >> d.signalDistance;
cin >> d.doorDirRequired;
cin >> d.doorDirActual;
cin >> d.doorOpenTime;
cin >> d.scheduledArrival;
cin >> d.actualArrival;
cin >> d.alignRange;
cin >> d.alignDistance;
string derailStr;
cin >> derailStr;
d.derailed = (derailStr == "true");
tree.addSegment(d);
}
tree.printResults();
return 0;
}
看到没有?非常的简单
看不懂的都是飞屋(环游记不会写)