706A - Beru-taxi - CodeForces Solution


brute force geometry implementation *900

Please click on ads to support us..

Python Code:

a,b=[int(i) for i in input().split()]
n=int(input())
s=10**10000
for i in range(n):
    x,y,v=[int(i) for i in input().split()]
    h=a
    f=b
    x,h=max(x,h),min(x,h)
    y,f=max(y,f),min(y,f)
    d=(x-h)**2 +(y-f)**2
    d**=0.5
    t=d/v  
    if t<s:
        s=t
print(round(s,15))

C++ Code:

#include <bits/stdc++.h>
using namespace std;
// #define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(V) (V).begin(), (V).end()
typedef long long ll;
#define ump unordered_map<int, int>
#define vi vector<int>
typedef pair<int, int> pii;

// Binary_Search, number_theory, math, basic Graph, STLS, Strings, Bit Masks, two pointers. This should help you solve div2 A and B maybe C depends on problem

void solve() {      
    double x1, y1; cin >> x1 >> y1;
    int n; cin >> n;
    double res = 1e9 * 1.0;
    for(int i = 0; i< n; i++) {
        double x2, y2, v;
        cin >> x2 >> y2 >> v;

        double p1 = (x2-x1), p2 = (y2-y1);
        double ed = sqrt((p1*p1 + p2*p2));

        double ans = ed/v;
        if(res > ans) {
            res = ans;
        }
    }
    printf("%.20f\n", res);
}

int main() {
    solve();
}


Comments

Submit
0 Comments
More Questions

1593C - Save More Mice
1217. Minimum Cost to Move Chips to The Same Position
347. Top K Frequent Elements
1503. Last Moment Before All Ants Fall Out of a Plank
430. Flatten a Multilevel Doubly Linked List
1290. Convert Binary Number in a Linked List to Integer
1525. Number of Good Ways to Split a String
72. Edit Distance
563. Binary Tree Tilt
1306. Jump Game III
236. Lowest Common Ancestor of a Binary Tree
790. Domino and Tromino Tiling
878. Nth Magical Number
2099. Find Subsequence of Length K With the Largest Sum
1608A - Find Array
416. Partition Equal Subset Sum
1446. Consecutive Characters
1618A - Polycarp and Sums of Subsequences
1618B - Missing Bigram
938. Range Sum of BST
147. Insertion Sort List
310. Minimum Height Trees
2110. Number of Smooth Descent Periods of a Stock
2109. Adding Spaces to a String
2108. Find First Palindromic String in the Array
394. Decode String
902. Numbers At Most N Given Digit Set
221. Maximal Square
1200. Minimum Absolute Difference
1619B - Squares and Cubes