Test instructions: Given n points that are collinear at three points, then ask how many sharp angles or right triangle you can make.
Analysis: Can be in turn, ask how many obtuse triangle, and then the total minus, the direct request will definitely time out, but you can enumerate each point, the point is an obtuse vertex, and then enumerate the other side, maintain with the edge is greater than 90 degrees and less than equal to 180 degrees of the number of points, here to be sorted by the polar angle, This can reduce the complexity of time, but will WA, to control the accuracy, but the accuracy is a mystery, said not.
The code is as follows:
#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <cstdio> #include <string> #include < cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include < queue> #include <algorithm> #include <vector> #include <map> #include <cctype> #include < cmath> #include <stack> #include <sstream> #include <list> #include <assert.h> #include < bitset> #include <numeric> #define DEBUG () puts ("++++") #define GCD (A, B) __gcd (A, b) #define Lson l,m,rt<<1 #define Rson m+1,r,rt<<1|1#define fi first#define se second#define pb push_back#define sqr (x) ((x) * (x)) #define MS (a , b) memset (A, B, sizeof a) #define SZ size () #define BE begin () #define ED end () #define PU push_up#define PD push_down#define CL Clear () #define LOWBIT (x)-x&x//#define ALL 1,n,1#define for (i,n,x) for (int i = (x); I < (n); ++i) #define Freop EnR freopen ("in.in", "R", stdin) #define FREOPENW freopen ("OUt.out "," w ", stdout) using namespace Std;typedef long long ll;typedef unsigned long long ull;typedef pair<int, int> p;const int inf = 0x3f3f3f3f;const LL LNF = 1e17;const double INF = 1e20;const Double PI = ACOs ( -1.0); const double EPS = 1 e-8;const int MAXN = 0 + 50;const int maxm = 1e6 + 10;const LL mod = 1000000000000000ll;const int dr[] = {-1, 1, 0,, 1, 1,-1, -1};const int dc[] = {0, 0, 1,-1, 1,-1, 1, -1};const char *de[] = {"0000", "0001", "0010", "0011", "0100", "01 "0110", "0111", "" "," "1001", "1010", "1011", "1100", "1101", "1110", "1111"};int N, m;const int mon[] = {0, 31, 28 ,,,,,,,,,,,,,,,,,,,,,,,, 31};const int monn[] = {0, ~, ~,------ OL is_in (int r, int c) {return R >= 0 && r < n && C >= 0 && C < m;} inline int readInt () {int x; scanf ("%d", &x); return x; }int A[MAXN], B[MAXN];d ouble p[maxn<<1];int main () {int kase = 0; while (scanf ("%d", &n) == 1 && N) {for (int i = 0; i < n; ++i) scanf ("%d%d", A + I, B + i); int ans = 0; for (int i = 0; i < n; ++i) {int cnt = 0; for (int j = 0; J < N; ++j) if (i! = j) p[cnt++] = atan2 (B[j]-b[i], a[j]-a[i]); Sort (p, p + cnt); for (int j = 0; J < cnt; ++j) p[j+cnt] = P[j] + PI * 2.; int k = 0, L = 0; for (int j = 0; J < cnt, ++j) {while (P[k]-p[j] + EPS <= PI/2.) ++k; while (P[l]-p[j] + EPS < PI) ++l; Ans + = l-k; }} ans = n * (n-1) * (n-2)/6-ans; if (n < 3) ans = 0; printf ("Scenario%d:\n", ++kase); printf ("There is%d sites for making valid tracks\n", ans); } return 0;}
Uvalive 4064 Magnetic Train Tracks (polar sort)