Репост из: TCS CodeVita Season 12 Solutions
TCS Cart
C++
100% Correct Code ✅
TCS CodeVita Zone 2
https://telegram.me/+_hn3cBQVbGliYTI9
#include
#include
#include
#include
#include
https://telegram.me/PLACEMENTLELO
using namespace std;
struct Point {
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
};
https://telegram.me/PLACEMENTLELO
Point rotatePoint(const Point &p, double theta) {
return Point(p.x * cos(theta) - p.y * sin(theta),
p.x * sin(theta) + p.y * cos(theta));
}
https://telegram.me/PLACEMENTLELO
pair getBoundingBox(const vector &polygon, double theta) {
double minX = 1e9, maxX = -1e9, minY = 1e9, maxY = -1e9;
for (const auto &p : polygon) {
Point rotated = rotatePoint(p, theta);
minX = min(minX, rotated.x);
maxX = max(maxX, rotated.x);
minY = min(minY, rotated.y);
maxY = max(maxY, rotated.y);
}
return {maxX - minX, maxY - minY};
}
https://telegram.me/PLACEMENTLELO
int main() {
int N;
cin >> N;
vector polygon(N);
for (int i = 0; i < N; ++i) {
cin >> polygon[i].x >> polygon[i].y;
}
https://telegram.me/PLACEMENTLELO
double placementlelo = 1e9;
double bestWidth = 0, bestHeight = 0;
https://telegram.me/PLACEMENTLELO
for (int i = 0; i < 360; ++i) {
double angle = i * M_PI / 180.0;
auto [width, height] = getBoundingBox(polygon, angle);
double area = width * height;
if (area < placementlelo) {
placementlelo = area;
bestWidth = width;
bestHeight = height;
}
}
https://telegram.me/PLACEMENTLELO
if (bestWidth > bestHeight) {
swap(bestWidth, bestHeight);
}
cout
C++
100% Correct Code ✅
TCS CodeVita Zone 2
https://telegram.me/+_hn3cBQVbGliYTI9
#include
#include
#include
#include
#include
https://telegram.me/PLACEMENTLELO
using namespace std;
struct Point {
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
};
https://telegram.me/PLACEMENTLELO
Point rotatePoint(const Point &p, double theta) {
return Point(p.x * cos(theta) - p.y * sin(theta),
p.x * sin(theta) + p.y * cos(theta));
}
https://telegram.me/PLACEMENTLELO
pair getBoundingBox(const vector &polygon, double theta) {
double minX = 1e9, maxX = -1e9, minY = 1e9, maxY = -1e9;
for (const auto &p : polygon) {
Point rotated = rotatePoint(p, theta);
minX = min(minX, rotated.x);
maxX = max(maxX, rotated.x);
minY = min(minY, rotated.y);
maxY = max(maxY, rotated.y);
}
return {maxX - minX, maxY - minY};
}
https://telegram.me/PLACEMENTLELO
int main() {
int N;
cin >> N;
vector polygon(N);
for (int i = 0; i < N; ++i) {
cin >> polygon[i].x >> polygon[i].y;
}
https://telegram.me/PLACEMENTLELO
double placementlelo = 1e9;
double bestWidth = 0, bestHeight = 0;
https://telegram.me/PLACEMENTLELO
for (int i = 0; i < 360; ++i) {
double angle = i * M_PI / 180.0;
auto [width, height] = getBoundingBox(polygon, angle);
double area = width * height;
if (area < placementlelo) {
placementlelo = area;
bestWidth = width;
bestHeight = height;
}
}
https://telegram.me/PLACEMENTLELO
if (bestWidth > bestHeight) {
swap(bestWidth, bestHeight);
}
cout