Last active
October 2, 2016 22:57
-
-
Save mgarg1/f139a652aa86df0dcd0d2c072f6f5a19 to your computer and use it in GitHub Desktop.
working soln1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <cassert> | |
using namespace std; | |
int main(){ | |
int N; | |
cin >> N; | |
const int CN=N; | |
vector<int> v1(N); | |
while(N--){ | |
cin >> v1[CN-N-1]; | |
} | |
assert(CN >= 2); | |
int sign = -1; | |
int sum = 0; | |
for (int i = 1; i < CN-1; ++i){ | |
sum += sign * 2 * v1[i]; | |
sign *= -1; | |
} | |
sum = sign * (sum + v1[0] + sign*v1[CN-1]); | |
float rad; | |
if(!(CN & 1)){ | |
// cout << "odd " <<sum << endl; | |
rad = sum / (float)3; | |
} | |
if(rad > 0 && rad < v1[CN-1]-v1[0] ){ | |
cout << rad << endl; | |
return 0; | |
} | |
cout << "no soln\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment