牛客多校第一场 Random Point in Triangle

https://ac.nowcoder.com/acm/contest/881/F

打表代码:

#include<bits/stdc++.h>
using namespace std;
double x[3]= {0,1,0},y[3]= {0,0,1};
double a,b;
double area(double x1,double y1,double x2,double y2,double x3,double y3)
{
    return fabs(x1*y2+x2*y3+x3*y1-x1*y3-x2*y1-x3*y2);
}
double cal()
{
    double t=area(a,b,x[1],y[1],x[2],y[2]);
    t=max(t,area(a,b,x[0],y[0],x[1],y[1]));
    t=max(t,area(a,b,x[0],y[0],x[2],y[2]));
    return t;
}
int main()
{
    //double a,b;
    int R=100;
    while(R--)
    {
        srand(time(NULL));
        double ans=0,t;
        int f=0;
        for(int i=1; i<=10000; i++)
        {
            f=rand()%2;
            a=rand()%1001/1001.0;
            b=rand()%1001/1001.0;
            t=a+b;
            if(t>1){
                a=a/t;
                b=b/t;
            }
            //cout<<a<<b<<'\n';
             ans+=cal();
        }
        cout<<36*ans/10000<<'\n';
    }

}

AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x[3],y[3];

int main()
{
    while(scanf("%lld%lld%lld%lld%lld%lld",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2])!=EOF){
        ll s=abs(x[1]*y[2]+x[2]*y[0]+x[0]*y[1]-x[0]*y[2]-x[1]*y[0]-x[2]*y[1]);
      //  cout<<s<<endl;
        cout<<11*s<<'\n';
    }
} 

 

转载于:https://www.cnblogs.com/liulex/p/11210326.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值