top of page

CCC 2020 S1: Surmising a Sprinter's Speed

Sort the points by time. Then loop through consecutive pairs to find the constant speed over each interval. The answer is the maximum of the speeds.


Time complexity:O(NlogN).


#include <iostream>
#include <utility>
#include <algorithm>
#include <iomanip>
using namespace std;
pair<double, double> A[100002];
int n;
double res = 0;
int main(){
	cin>>n;
	for(int i = 0; i < n; i++)
		cin>>A[i].first>>A[i].second;
	sort(A, A+n);
	for(int i = 1; i < n; i++){
		res = max(res, abs(A[i].second-A[i-1].second)/(A[i].first-A[i-1].first));
	}
	cout<<fixed<<setprecision(10)<<res;
	return 0;
}

Recent Posts

See All

CCC '24 J5 - Harvest Waterloo

#include<iostream> #include <vector> #include <algorithm> #include <cmath> #include <stack> using namespace std; int main() { int r, c,...

CCC '24 J4 - Troublesome Keys

s1 = input() s2 = input() silly = '' silly_o = '' quiete = '-' i = 0 j = 0 while i < len(s1) and j < len(s2): if s1[i] != s2[j]: if...

CCC '22 J5 - Square Pool

#include<iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; bool rowcom(pair<int, int> a, pair<int,...

Comments


One-time Donations
I hope I can solve all CCC problems!,
Please e-transfer cccottawa862008@gmail.com

Subscribe to AIOICode newsletter

I'm a title. ​Click here to edit me.

Thanks for submitting!

  • Twitter
  • Facebook
  • Linkedin

© 2023 by AIOICode.

bottom of page