【BZOJ2729】[HNOI2012]排队

1 1

Sample Output

12

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
struct cbig
{
int len;
int v[200000];
cbig(){len=0,memset(v,0,sizeof(v));}
cbig(int x)
{
len=0,memset(v,0,sizeof(v));
while(x)	v[++len]=x%10,x/=10;
}
void operator *= (int b)
{
int i;
for(i=1;i<=len;i++)	v[i]*=b;
for(i=1;i<=len;i++)	v[i+1]+=v[i]/10,v[i]%=10;
while(v[len+1])	len++,v[len+1]+=v[len]/10,v[len]%=10;
}
void operator -= (cbig b)
{
int i;
for(i=1;i<=b.len;i++)	v[i]-=b.v[i];
for(i=1;i<=len;i++)
{
if(v[i]<0)	v[i+1]+=v[i]/10,v[i]%=10;
if(v[i]<0)	v[i+1]--,v[i]+=10;
}
while(len&&!v[len])	len--;
}
}ans1,ans2;
void A(cbig &ret,int a,int b)
{
for(int i=a-b+1;i<=a;i++)	ret*=i;
}
int main()
{
int i,n,m;
scanf("%d%d",&n,&m);
ans1=cbig(1),A(ans1,n+2,n+2),A(ans1,n+3,m);
ans2=cbig(2),A(ans2,n+1,n+1),A(ans2,n+2,m);
ans1-=ans2;
if(!ans1.len)	printf("0");
else	for(i=ans1.len;i;i--)	printf("%d",ans1.v[i]);
return 0;
}
posted @ 2017-08-15 19:29  CQzhangyu  阅读(313)  评论(0编辑  收藏  举报