Skip to content

Instantly share code, notes, and snippets.

@saadismail
Created March 6, 2018 16:59
Show Gist options
  • Select an option

  • Save saadismail/7a363320c923a9e0a71977aa21fc097d to your computer and use it in GitHub Desktop.

Select an option

Save saadismail/7a363320c923a9e0a71977aa21fc097d to your computer and use it in GitHub Desktop.
#include <iostream>
#include <climits>
#include <cmath>
using namespace std;
int n;
double x, y;
double dist;
double calcdis (double x1, double y1) {
return sqrt(pow(x-x1, 2) + pow(y-y1, 2));
}
void solve(int currSec, double cx, double cy, int angle) {
if (currSec > n) return;
dist = calcdis(cx + (10 * cos(M_PI * angle / 180.0)), cy + (10 * sin(M_PI * angle / 180.0)));
solve(currSec+1, cx + (10 * cos(M_PI * angle / 180.0)), cy + (10 * sin(M_PI * angle / 180.0)), angle);
solve(currSec+1, cx, cy, (angle+45) % 360);
}
int main(void) {
int t; cin >> t;
while (t--) {
cout << dist << endl;
cin >> n >> x >> y;
dist = calcdis(0, 0);
solve(1, 0.0, 0.0, 0);
solve(1, 0.0, 0.0, 45);
cout << dist << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment