SSLOJ 1143.三角形(triangle)

目录:


题目:

传送门


分析:

这道题不需要什么高端的算法,只要运用些数论知识——斜率就好了


代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>  
#include<cstdlib>
#include<algorithm>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<ctime>
#include<iomanip>
#include<string>
#include<bitset>
#include<deque>
#include<set>
#define LL long long
#define h happy
#define XJQ 0x7f7f7f7f
using namespace std;
inline LL read() {
    LL d=0,f=1;char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
    return d*f;
}
double slope[3001];
int x[3001][3];
int main()
{
    int n=read();
    for(int i=1;i<=n;i++) x[i][1]=read(),x[i][2]=read();
    LL len,s=(n-1)*(n-2);
    s=s*n/6;
    for(int i=1;i<n-1;i++)
      {
        len=0;
        for(int j=i+1;j<=n;j++)
          if(x[i][1]-x[j][1]!=0) slope[++len]=(double)(x[i][2]-x[j][2])/(double)(x[i][1]-x[j][1]);
          else slope[++len]=XJQ;
        sort(slope+1,slope+1+len);
        int t=1;
        for(int j=2;j<=len;j++)
          if(slope[j-1]==slope[j]) t++;
          else s-=(t-1)*t/2,t=1;
        s-=(t-1)*t/2;
      }
    cout<<s;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值