BZOJ3841: ZCC Loves Intersection

31 篇文章 0 订阅
12 篇文章 0 订阅

两条线段有交的充要条件是每一维上都有交qwq
因为每个线段都平行一个坐标轴,他的表示应该是(l~r,x1,x2,x3…xn)
A和B相交和A和C相交显然没有任何关系
算粗A,B相交的概率,乘上两两的组合数就行了
两条线段相交的概率画一下柿子就行了吧
然后写个高精..

code:

#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxl = 1100;
ll gcd(ll a,ll b){return !a?b:gcd(b%a,a);}

int n,d;
struct Num
{
    ll a[maxl]; int len;
}fz,fm,temp;
ll Mod(Num &x,ll b)
{
    ll tmp=0;
    for(int i=x.len;i>=1;i--)
        tmp=(tmp*10ll+x.a[i])%b;
    return tmp;
}
void div(Num &x,ll b)
{
    int len=x.len; ll tmp=0;
    for(int i=len;i>=1;i--)
    {
        tmp=tmp*10ll+x.a[i];
        x.a[i]=tmp/b; tmp%=b;
    }
    while(!x.a[len]) len--;
    x.len=len;
}
void mul(Num &x,ll b)
{
    int len=x.len;
    for(int i=len;i>=1;i--) x.a[i]*=b;
    for(int i=1;i<=len;i++) x.a[i+1]+=x.a[i]/10ll,x.a[i]%=10ll;
    while(x.a[len+1])
    {
        len++; 
        x.a[len+1]+=x.a[len]/10ll,x.a[len]%=10ll;
    }
    x.len=len;
}
void add(Num &x,Num y)
{
    int len=max(x.len,y.len);
    for(int i=1;i<=len;i++) 
    {
        x.a[i]+=y.a[i];
        x.a[i+1]+=x.a[i]/10ll,x.a[i]%=10ll;
    }
    if(x.a[len+1]) len++;
    x.len=len;
}
void MUL(ll b)
{
    ll g=gcd(Mod(fm,b),b);
    ll tmp=b/g; if(g>1ll) div(fm,g);
    if(tmp>1ll) mul(fz,tmp);
}
void DIV(ll b)
{
    ll g=gcd(Mod(fz,b),b);
    ll tmp=b/g; if(g>1ll) div(fz,g);
    if(tmp>1ll) mul(fm,tmp);
}
void output(Num &x){for(int i=x.len;i>=1;i--) putchar('0'+x.a[i]);}
void Out()
{
    MUL((ll)d*(d-1)/2ll);
    output(fz);
    if(!(fm.len==1&&fm.a[1]==1)) putchar('/'),output(fm);
    putchar('\n');
}

int main()
{
    while(scanf("%d%d",&n,&d)!=EOF)
    {
        memset(fz.a,0,sizeof fz.a); fz.a[1]=1ll,fz.len=1;
        fm=temp=fz;

        mul(fz,n); mul(fz,n);
        temp.len=2,temp.a[1]=6ll,temp.a[2]=1ll; add(fz,temp);
        temp.len=1,temp.a[1]=8ll,temp.a[2]=0ll; mul(temp,n); add(fz,temp);
        DIV(n); DIV(n); DIV(9ll);

        for(int i=3;i<=d;i++) DIV(n);
        Out();
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值