UVA-12123 Magnetic Train Tracks

Source: Internet
Author: User
Tags cas

Description

The rail roads of Japan are being redesigned. So the governent are planning to install ultra-modern magnetic trains instead of the current normal trains. As fuel price has gone high and nations has shut down their nuclear plants so the price of Electricity/battery is also s KY High. To reduce power consumption the Japanese government was trying to descourage people from riding trains–as a result of the TI Cket Price was also kept sky high and it was strictly proportional to the square of the distance between.

All the trains move in clockwise or counter clockwise order in a closed triangular track. These triangular tracks can be a formed by connecting any three stations in clockwise or counterclockwise order. For simplicity you can assume this a station was denoted by a, point in a, dimensional Cartesian coordinate system. But these triangular tracks and ticket pricing policy can create new troubles. As the ticket price between and stations is proportional to the square of the distance, people often avoid the shortest ro Ute to destination and rather choose the longer one through another station. This causes more electricity expense per passenger and creates unwanted crowd in the stations. So the government would prefer does such tracks.

/td>

Figure 1:the figure above shows 6 places. It also shows all possible triangular tracks (not necessarily valid site) by connecting them. The green track was one invalid track site and on the other hand the red track was one valid track site. There is five other valid track sites in the above figure. FV

For example in the "the left" can see a closed triangular track marked with green. If someone wants to go-station D-station E He can go directly by riding a clockwise train or can go via station C By riding a counter clockwise Train:that was he first buys ticket from station D to C and then he buys ticket of station C To E. The current ticket pricing system, the route via C (which is also much longer) would be cheaper. So the site CED is the not-a place-to-build a track. For the similar reasons AEB are a valid site for building track. On a valid track the shortest distance between any and stations is also the unique cheapest route between them. Given the coordinate of all stations you'll have to find the number of sites (a group of three places) for valid tracks.

Input

The input file contains at the most sets of inputs. The description of each set is given below:

Each set starts with an n (2<n<1201) which denotes the number of stations. Each of the next n lines contains-integer xi, yi (0≤xi, yi≤10000) which denotes the Cartesian coordinate of the i-th s Tation. You can assume this a track can is built via through any three stations, no three places would be collinear to avoid the PR Oblem of degenerate tracks and the connecting railroad between both stations can always being represented by the straight line connecting them.

Output for each set of input produce of output. The first line contains the serial of output and the second line displays the total number of sites where a track can be B Uilt. Look at the output for sample input for details.

Sample input Output for sample input

Scenario 1:

There is 6 sites for making valid tracks

Scenario 2:

There is 0 sites for making valid tracks

Problem Setter:shahriar Manzoor, special Thanks:derek Kisman

Test instructions: N a point on a given plane that has no three-point collinear, and how many sharp angles or right triangle are made of these points

Idea: First of all clear a right angle and obtuse angles are the only corresponding to a triangle, so we do not go to statistical comparison difficult to calculate the acute angle, the first calculation of the possible precision of obtuse, and then minus

 #include <iostream> #include <cstdio> #include <cstring> #include < Algorithm> #include <cmath>typedef Long long ll;using namespace Std;const int maxn = 1250;const double pi= ACOs (-1 .0); const double EPS = 1e-9;struct point {double X, y;} P[maxn];d ouble du[maxn<<1];int main () {int T, N, cas = 1;whi Le (scanf ("%d", &n)! = EOF && N) {for (int i = 0; i < n; i++) scanf ("%lf%lf", &p[i].x, &P[I].Y); ll TMP = 0;for (int i = 0; i < n; i++) {if (i) swap (P[i], p[0]), for (int k = 1; k < n; k++) du[k] = atan2 (P[K].Y-P[0].Y,  p[k].x-p[0].x); sort (du+1, du+n); for (int k = 1; k < n; k++) du[k+n-1] = Du[k] + 2 * pi;int cnt1 = 1, Cnt2 = 1;for (int k = 1; K < n; k++) {while (Du[cnt1]-du[k] <= 0.5*pi-eps) cnt1++;while (Du[cnt2]-du[k] <= pi) cnt2++;tmp + = Cnt2-cnt1;}} ll ans = n (n-1) * (n-2)/6-tmp;printf ("Scenario%d:\n", cas++);p rintf ("There is%lld sites for making valid tracks\n", ans);} return 0;} 


UVA-12123 Magnetic Train Tracks

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.