CF13D Triangles

This is a mathematical knowledge required \ (DP? \)

Idea

First of all, how to determine whether a point is inside the triangle - we assume that \ (\ bigtriangleup ABC \) as well as to determine the point \ (P \) , if \ (P \) in \ (ABC \) inside, then the edge \ (AB \) , the point \ (P \) and the point \ (C \) in the side \ (AB \) ipsilateral; on edge \ (the BC \) , the point \ (P \) and a point \ (a \) in the ipsilateral side BC, the same, while \ (AC \) is true. We can use this idea to achieve cross product, cross product \ (> 0 \) is on the same side, cross-product \ (<0 \) is a different side.

We set up an origin \ (O \) (coordinates should be outside the input range), each looking for two points in the red dot, and seeking two points \ (O \) triangles in the number of blue dots with \ (dp [i] [j ] \) preserved;

We assume that the red dot selected three dots triangle marked \ (ABC \) , then

\ (\ Bigtriangleup ABC \ text {the number of blue dots} = \ bigtriangleup OAB + \ bigtriangleup OBC - \ bigtriangleup OAC \)

Code

Remember to open the \ (Long Long ~ \) , or even the sample would go

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<queue>
#define int long long
#define maxn 505
#define inf 2147483647
#define mod 998244353
#define eps 1e-6
#define pi acos(-1.0)
#define de(x) ((x)*(x))
using namespace std; 
inline int read(){
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)) {x=x*10+ch-48;ch=getchar();}
    return x*f;
}
int dp[maxn][maxn];
struct Node{
    int x, y;
    Node() {}
    Node(int xi, int yi):x(xi), y(yi){}
    Node operator - (const Node &N) const{return Node(x-N.x, y-N.y);}
    inline int operator * (const Node &N) const{return x*N.y-y*N.x;}
}red[maxn],blue[maxn];
signed main(){
    int n=read(),m=read();
    for(int i=0;i<n;i++) red[i].x=read(),red[i].y=read();
    for(int i=0;i<m;i++) blue[i].x=read(),blue[i].y=read();
    Node a=Node(-1000000001,-1000000001);
    for(int i=0;i<n;i++)
    for(int j=0;j<n;j++){
        if((red[i]-a)*(red[j]-a)<=0) continue;
        for(int k=0;k<m;k++){
            if((red[i]-a)*(blue[k]-a)>0&&(red[j]-red[i])*(blue[k]-red[i])>0&&(a-red[j])*(blue[k]-red[j])>0)
                dp[i][j]++;
        }
        dp[j][i]=-dp[i][j];
    }
    int ans=0;
    for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
    for(int k=j+1;k<n;k++)
    ans+=(dp[i][j]+dp[j][k]+dp[k][i]==0);
    printf("%d",ans);
    return 0;
}

Guess you like

Origin www.cnblogs.com/cbyyc/p/11483246.html