Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define fixlen 10000
- #include <stdio.h>
- #include <math.h>
- double getCos(double x, double y, double x1, double y1, double x2, double y2);
- double getVisionAngle(double* px, double* py, int len);
- int main(void)
- {
- double pointsX[fixlen], pointsY[fixlen], a;
- FILE *fin;
- int len = 0;
- fin = fopen("input.txt", "r");
- if (!fin)
- {
- printf("File opening error\n");
- return -1;
- }
- for (int i = 0; i < fixlen; i++)
- {
- if (fscanf(fin, "%lf", &a) != 1) break;
- pointsX[i] = i;
- if (fscanf(fin, "%lf", &a) != 1) break;
- pointsY[i] = i;
- len++;
- }
- printf("%lf" , getVisionAngle(pointsX, pointsY, len));
- fclose(fin);
- return 0;
- }
- double getCos(double x, double y, double x1, double y1, double x2, double y2)
- {
- double a, b, c, cos;
- a = pow((x1-x2), 2) + pow((y1-y2), 2);
- b = pow((x-x2), 2) + pow((y-y2), 2);
- c = pow((x1-x), 2) + pow((y1-y), 2);
- cos = (b + c - a) / (2 * sqrt(b*c));
- return cos;
- }
- double getVisionAngle(double* px, double* py, int len)
- {
- double x, y, mincos, curcos, x1, x2, y1, y2;
- scanf("%lf %lf", &x, &y);
- mincos = 2;
- for (int i = 0; i < len - 1; i++)
- {
- for (int j = i + 1; j < len; j++)
- {
- x1 = px[i];
- y1 = py[i];
- x2 = px[j];
- y2 = py[j];
- curcos = getCos(x, y, x1, y1, x2, y2);
- if (curcos < mincos) mincos = curcos;
- }
- }
- mincos = acos(mincos);
- return mincos;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement