UVA 12123-magnetic Train Tracks (counting problem)

Source: Internet
Author: User

Title Link: 12123-magnetic Train TracksTest Instructions: Given n points, ask for a few acute triangle. idea: And UVA 11529 is the same problem, enumerate one to do the origin, and then the rest of the point according to the origin of the polar sort, and then use the second pointer to go through, to find the angle is less than 90 degrees of acute angle, and then buckle down the number of obtuse triangle to get, And then, in total condition, the obtuse angle is sharp or right-angled.Code:
#include <stdio.h> #include <string.h> #include <math.h> #include <algorithm>using namespace Std;const double eps = 1e-9;const double pi = ACOs ( -1.0); const int N = 1205;int n;struct Point {double X, y;void read () {s CANF ("%lf%lf", &x, &y); }} P[n];d ouble r[n * 2];int C (int N, int m) {if (N < m) return 0;int ans = 1;for (int i = 0; i < m; i++) ans = ans * (n-i)/(i + 1); return ans;} Double Cal (Point A, point B) {return atan2 (B.Y-A.Y, b.x-a.x);} int solve (int num) {int tn = 0;for (int i = 0; i < n; i++) {if (i = = num) continue;r[tn++] = Cal (P[num], p[i]);} sort ( R, R + TN); for (int i = 0, i < TN; i++) R[tn + i] = R[i] + 2 * pi;int j = 1;int ans = 0;for (int i = 0; I < TN; i++) {while (FA BS (R[j]-r[i])-PI/2 <=-eps) J++;ans + = j-i-1; } return C (TN, 2)-ans;} int main () {int cas = 0;while (~scanf ("%d", &n) && N) {for (int i = 0; i < n; i++) p[i].read (); int ans = 0;f or (int i = 0; i < n; i++) ans + = solve (i);p rintf ("Scenario%d:\n", ++cas);p rintf ("There is%d sites for making valid tracks\n", C (n, 3)-ans); }return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.