Algorithm
Problem Statement for PipeCuts
Problem Link- https://community.topcoder.com/stat?c=problem_statement&pm=3994&rd=6532 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <bits/stdc++.h>
using namespace std;
class PipeCuts {
public:
double probability(vector<int> weldLocations, int L) {
sort(weldLocations.begin(), weldLocations.end());
int all = 0, cnt = 0;
for(int i = 0; i < weldLocations.size(); ++i) {
for(int j = i + 1; j < weldLocations.size(); ++j) {
++all;
int c1 = weldLocations[i], c2 = weldLocations[j] - weldLocations[i], c3 = 100 - weldLocations[j];
if(c1 > L || c2 > L || c3 > L)
++cnt;
}
}
return 1.0 * cnt / all;
}
};
Copy The Code &
Try With Live Editor
Input
{25, 50, 75}
25
25
Output
1.0
Demonstration
TopCoder Solution SRM233-D1-250 Problem Statement for PipeCuts C,C++, Java, Js and Python ,SRM233-D1-250,TopCoder Solution