Solo Rider
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
typedef struct {
int x, y;
} Point;
typedef struct {
char name[20];
Point location;
} Passenger;
typedef struct {
char number[20];
Point location;
} Vehicle;
int manhattanDistance(Point p1, Point p2) {
return abs(p1.x - p2.x) + abs(p1.y - p2.y);
}
Vehicle* findNearestVehicle(Passenger passenger, Vehicle* vehicles, int m, int* assigned) {
int i;
int minDistance = INT_MAX;
Vehicle* nearestVehicle = NULL;
for (i = 0; i < m; i++) {
if (!assigned[i]) {
int distance = manhattanDistance(passenger.location, vehicles[i].location);
if (distance < minDistance || (distance == minDistance && strcmp(vehicles[i].number, nearestVehicle->number) < 0)) {
minDistance = distance;
nearestVehicle = &vehicles[i];
}
}
}
assigned[nearestVehicle - vehicles] = 1;
return nearestVehicle;
}
int main() {
int n, m,i;
scanf("%d %d", &n, &m);
Passenger passengers[n];
for ( i = 0; i < n; i++) {
scanf("%s %d %d", passengers[i].name, &passengers[i].location.x, &passengers[i].location.y);
}
Vehicle vehicles[m];
for ( i = 0; i < m; i++) {
scanf("%s %d %d", vehicles[i].number, &vehicles[i].location.x, &vehicles[i].location.y);
}
int assigned[m];
memset(assigned, 0, sizeof(assigned));
int totalDistance = 0;
for ( i = 0; i < n; i++) {
Vehicle* assignedVehicle = findNearestVehicle(passengers[i], vehicles, m, assigned);
totalDistance += manhattanDistance(passengers[i].location, assignedVehicle->location);
}
printf("%d\n", totalDistance);
return 0;
}
Solo rider
Only public Test Cases Passed
I'm Trying to Modify So for now you can try this
I will update new soon
Keep sharing
https://t.me/TCS_Codevita_Exam_Help
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
typedef struct {
int x, y;
} Point;
typedef struct {
char name[20];
Point location;
} Passenger;
typedef struct {
char number[20];
Point location;
} Vehicle;
int manhattanDistance(Point p1, Point p2) {
return abs(p1.x - p2.x) + abs(p1.y - p2.y);
}
Vehicle* findNearestVehicle(Passenger passenger, Vehicle* vehicles, int m, int* assigned) {
int i;
int minDistance = INT_MAX;
Vehicle* nearestVehicle = NULL;
for (i = 0; i < m; i++) {
if (!assigned[i]) {
int distance = manhattanDistance(passenger.location, vehicles[i].location);
if (distance < minDistance || (distance == minDistance && strcmp(vehicles[i].number, nearestVehicle->number) < 0)) {
minDistance = distance;
nearestVehicle = &vehicles[i];
}
}
}
assigned[nearestVehicle - vehicles] = 1;
return nearestVehicle;
}
int main() {
int n, m,i;
scanf("%d %d", &n, &m);
Passenger passengers[n];
for ( i = 0; i < n; i++) {
scanf("%s %d %d", passengers[i].name, &passengers[i].location.x, &passengers[i].location.y);
}
Vehicle vehicles[m];
for ( i = 0; i < m; i++) {
scanf("%s %d %d", vehicles[i].number, &vehicles[i].location.x, &vehicles[i].location.y);
}
int assigned[m];
memset(assigned, 0, sizeof(assigned));
int totalDistance = 0;
for ( i = 0; i < n; i++) {
Vehicle* assignedVehicle = findNearestVehicle(passengers[i], vehicles, m, assigned);
totalDistance += manhattanDistance(passengers[i].location, assignedVehicle->location);
}
printf("%d\n", totalDistance);
return 0;
}
Solo rider
Only public Test Cases Passed
I'm Trying to Modify So for now you can try this
I will update new soon
Keep sharing
https://t.me/TCS_Codevita_Exam_Help
SAB LOG SUBSCRIBE KARO.. EK MIN LAGEGI and TUMHARA EK QUESTION KA CODE AA JAYEGA
https://www.youtube.com/shorts/wfhCTLmxlEw
https://www.youtube.com/shorts/wfhCTLmxlEw
https://www.youtube.com/shorts/xcmj7hifWro
JALDI SUBSCRIBE KARO GUYZ... AAGE KE CODE BHI UPLOAD KRNE H
JALDI SUBSCRIBE KARO GUYZ... AAGE KE CODE BHI UPLOAD KRNE H
def minimum_vehicles(weights, max_limit):
# Filter out zero weights and sort the remaining weights in descending order
sorted_weights = sorted(filter(lambda x: x != 0, weights), reverse=True)
left, right = 0, len(sorted_weights) - 1
vehicles = 0
while left <= right:
if sorted_weights[left] + sorted_weights[right] <= max_limit:
right -= 1
left += 1
vehicles += 1
return vehicles
# Example usage:
weights = list(map(int, input().split()))
max_limit = int(input())
result = minimum_vehicles(weights, max_limit)
print(result, end="")
Warehouse public PRIVATE passed ✅✅✅... python 3
# Filter out zero weights and sort the remaining weights in descending order
sorted_weights = sorted(filter(lambda x: x != 0, weights), reverse=True)
left, right = 0, len(sorted_weights) - 1
vehicles = 0
while left <= right:
if sorted_weights[left] + sorted_weights[right] <= max_limit:
right -= 1
left += 1
vehicles += 1
return vehicles
# Example usage:
weights = list(map(int, input().split()))
max_limit = int(input())
result = minimum_vehicles(weights, max_limit)
print(result, end="")
Warehouse public PRIVATE passed ✅✅✅... python 3
Listen PRESENTATION ERROR se Kuch Fark nhi padta.. Your code is Still Submitted Perfectly
YOUTUBE PR 100 SUBS KRDO BS.. I WILL UPLOAD Pick up service ✅
https://www.youtube.com/shorts/xcmj7hifWro
JALDI KARO
https://www.youtube.com/shorts/xcmj7hifWro
JALDI KARO
import math
def calculate_distance(point1, point2):
return abs(point1[0] - point2[0]) + abs(point1[1] - point2[1])
def assign_vehicles(passengers, vehicles):
allocated_vehicles = {}
total_distance = 0
for passenger in sorted(passengers):
min_distance = math.inf
closest_vehicle = ""
passenger_coordinates = passengers[passenger]
for vehicle in vehicles:
if vehicles[vehicle] == "":
vehicle_coordinates = vehicles[vehicle + "_coordinates"]
distance = calculate_distance(passenger_coordinates, vehicle_coordinates)
if distance < min_distance or (distance == min_distance and vehicle < closest_vehicle):
min_distance = distance
closest_vehicle = vehicle
allocated_vehicles[passenger] = closest_vehicle
vehicles[closest_vehicle] = passenger
total_distance += min_distance
return total_distance
N, M = map(int, input().split())
passengers = {}
vehicles = {}
for _ in range(N):
name, x, y = input().split()
passengers[name] = (int(x), int(y))
for _ in range(M):
vehicle, x, y = input().split()
vehicles[vehicle] = ""
vehicles[vehicle + "_coordinates"] = (int(x), int(y))
minimum_distance = assign_vehicles(passengers, vehicles)
print(minimum_distance,end="")
Solo rider✅ Public PRIVATE passed ✅✅✅... python 3
def calculate_distance(point1, point2):
return abs(point1[0] - point2[0]) + abs(point1[1] - point2[1])
def assign_vehicles(passengers, vehicles):
allocated_vehicles = {}
total_distance = 0
for passenger in sorted(passengers):
min_distance = math.inf
closest_vehicle = ""
passenger_coordinates = passengers[passenger]
for vehicle in vehicles:
if vehicles[vehicle] == "":
vehicle_coordinates = vehicles[vehicle + "_coordinates"]
distance = calculate_distance(passenger_coordinates, vehicle_coordinates)
if distance < min_distance or (distance == min_distance and vehicle < closest_vehicle):
min_distance = distance
closest_vehicle = vehicle
allocated_vehicles[passenger] = closest_vehicle
vehicles[closest_vehicle] = passenger
total_distance += min_distance
return total_distance
N, M = map(int, input().split())
passengers = {}
vehicles = {}
for _ in range(N):
name, x, y = input().split()
passengers[name] = (int(x), int(y))
for _ in range(M):
vehicle, x, y = input().split()
vehicles[vehicle] = ""
vehicles[vehicle + "_coordinates"] = (int(x), int(y))
minimum_distance = assign_vehicles(passengers, vehicles)
print(minimum_distance,end="")
Solo rider✅ Public PRIVATE passed ✅✅✅... python 3
I am not asking money 💰💰
We want you to share the Channel to everyone
Then I will share all correct 💯 code very soon
Share @TCS_Codevita_Exam_Help
Share ✅ share✅ share✅
We want you to share the Channel to everyone
Then I will share all correct 💯 code very soon
Share @TCS_Codevita_Exam_Help
Share ✅ share✅ share✅