BZOJ2729:[HNOI2012]排队(组合数学)
Description
Input
Output
Sample Input
Sample Output
Solution
一种情况是两个老师中间只有一个人且这个人是女生。
即$A(n,n)*A(n+1,1)*A(2,2)*A(m,1)*A(n+2,m-1)$
另一种情况是两个老师中间不是只有一个女生,也就是两个老师中间一定有男生。
即$A(n,n)*A(n+1,2)*A(n+3,m)$
Code
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define MAX_L 20005
using namespace std; class bign
{
public:
int len, s[MAX_L];
bign();
bign(const char*);
bign(int);
bool sign;
string toStr() const;
friend istream& operator>>(istream &,bign &);
friend ostream& operator<<(ostream &,bign &);
bign operator=(const char*);
bign operator=(int);
bign operator=(const string);
bool operator>(const bign &) const;
bool operator>=(const bign &) const;
bool operator<(const bign &) const;
bool operator<=(const bign &) const;
bool operator==(const bign &) const;
bool operator!=(const bign &) const;
bign operator+(const bign &) const;
bign operator++();
bign operator++(int);
bign operator+=(const bign&);
bign operator-(const bign &) const;
bign operator--();
bign operator--(int);
bign operator-=(const bign&);
bign operator*(const bign &)const;
bign operator*(const int num)const;
bign operator*=(const bign&);
bign operator/(const bign&)const;
bign operator/=(const bign&);
bign operator%(const bign&)const;
bign factorial()const;
bign Sqrt()const;
bign pow(const bign&)const;
void clean();
~bign();
}; bign::bign()
{
memset(s,,sizeof(s));
len=;
sign=;
} bign::bign(const char *num)
{
*this=num;
} bign::bign(int num)
{
*this=num;
} string bign::toStr() const
{
string res;
res="";
for (int i=; i<len; i++)
res=(char)(s[i]+'')+res;
if (res=="")
res="";
if (!sign&&res!="")
res="-"+res;
return res;
} istream &operator>>(istream &in, bign &num)
{
string str;
in>>str;
num=str;
return in;
} ostream &operator<<(ostream &out, bign &num)
{
out<<num.toStr();
return out;
} bign bign::operator=(const char *num)
{
memset(s,,sizeof(s));
char a[MAX_L]="";
if (num[]!='-')
strcpy(a,num);
else
for (int i=,l=strlen(num); i<l; i++)
a[i-]=num[i];
sign=!(num[]=='-');
len=strlen(a);
for (int i=; i<strlen(a); i++)
s[i]=a[len-i-]-;
return *this;
} bign bign::operator=(int num)
{
char temp[MAX_L];
sprintf(temp,"%d",num);
*this=temp;
return *this;
} bign bign::operator=(const string num)
{
const char *tmp;
tmp=num.c_str();
*this=tmp;
return *this;
} bool bign::operator<(const bign &num) const
{
if (sign^num.sign)
return num.sign;
if (len!=num.len)
return len<num.len;
for (int i=len-; i>=; i--)
if (s[i]!=num.s[i])
return sign?(s[i]<num.s[i]):(!(s[i]<num.s[i]));
return !sign;
} bool bign::operator>(const bign&num)const
{
return num<*this;
} bool bign::operator<=(const bign&num)const
{
return !(*this>num);
} bool bign::operator>=(const bign&num)const
{
return !(*this<num);
} bool bign::operator!=(const bign&num)const
{
return *this>num || *this<num;
} bool bign::operator==(const bign&num)const
{
return !(num!=*this);
} bign bign::operator+(const bign &num) const
{
if (sign^num.sign)
{
bign tmp=sign?num:*this;
tmp.sign=;
return sign?*this-tmp:num-tmp;
}
bign result;
result.len=;
int temp=;
for (int i=; temp || i<(max(len, num.len)); i++)
{
int t=s[i]+num.s[i]+temp;
result.s[result.len++]=t % ;
temp=t/;
}
result.sign=sign;
return result;
} bign bign::operator++()
{
*this=*this+;
return *this;
} bign bign::operator++(int)
{
bign old=*this;
++(*this);
return old;
} bign bign::operator+=(const bign &num)
{
*this=*this+num;
return *this;
} bign bign::operator-(const bign &num) const
{
bign b=num,a=*this;
if (!num.sign && !sign)
{
b.sign=;
a.sign=;
return b-a;
}
if (!b.sign)
{
b.sign=;
return a+b;
}
if (!a.sign)
{
a.sign=;
b=bign()-(a+b);
return b;
}
if (a<b)
{
bign c=(b-a);
c.sign=false;
return c;
}
bign result;
result.len=;
for (int i=, g=; i<a.len; i++)
{
int x=a.s[i]-g;
if (i<b.len) x -= b.s[i];
if (x >= ) g=;
else
{
g=;
x += ;
}
result.s[result.len++]=x;
}
result.clean();
return result;
} bign bign::operator * (const bign &num)const
{
bign result;
result.len=len+num.len; for (int i=; i<len; i++)
for (int j=; j<num.len; j++)
result.s[i+j] += s[i] * num.s[j]; for (int i=; i<result.len; i++)
{
result.s[i+] += result.s[i]/;
result.s[i] %= ;
}
result.clean();
result.sign=!(sign^num.sign);
return result;
} bign bign::operator*(const int num)const
{
bign x=num;
bign z=*this;
return x*z;
}
bign bign::operator*=(const bign&num)
{
*this=*this * num;
return *this;
} bign bign::operator /(const bign&num)const
{
bign ans;
ans.len=len-num.len+;
if (ans.len<)
{
ans.len=;
return ans;
} bign divisor=*this, divid=num;
divisor.sign=divid.sign=;
int k=ans.len-;
int j=len-;
while (k >= )
{
while (divisor.s[j]==) j--;
if (k > j) k=j;
char z[MAX_L];
memset(z, , sizeof(z));
for (int i=j; i >= k; i--)
z[j-i]=divisor.s[i]+'';
bign dividend=z;
if (dividend<divid)
{
k--;
continue;
}
int key=;
while (divid*key <= dividend) key++;
key--;
ans.s[k]=key;
bign temp=divid*key;
for (int i=; i<k; i++)
temp=temp * ;
divisor=divisor-temp;
k--;
}
ans.clean();
ans.sign=!(sign^num.sign);
return ans;
} bign bign::operator/=(const bign&num)
{
*this=*this/num;
return *this;
} bign bign::operator%(const bign& num)const
{
bign a=*this, b=num;
a.sign=b.sign=;
bign result, temp=a/b*b;
result=a-temp;
result.sign=sign;
return result;
} bign bign::pow(const bign& num)const
{
bign result=;
for (bign i=; i<num; i++)
result=result*(*this);
return result;
} bign bign::factorial()const
{
bign result=;
for (bign i=; i <= *this; i++)
result*=i;
return result;
} void bign::clean()
{
if (len==) len++;
while (len> && s[len-]=='\0')
len--;
} bign bign::Sqrt()const
{
if(*this<)return -;
if(*this<=)return *this;
bign l=,r=*this,mid;
while(r-l>)
{
mid=(l+r)/;
if(mid*mid>*this) r=mid;
else l=mid;
}
return l;
} bign::~bign()
{
} bign A(int n,int m)
{
bign ans;
ans=;
for (int i=n-m+; i<=n; ++i) ans*=i;
return ans;
} int n,m; int main()
{
scanf("%d%d",&n,&m);
bign ans=A(n,n)*A(n+,)*A(n+,m)+A(n,n)*A(n+,)*A(,)*A(m,)*A(n+,m-);
cout<<ans;
}
BZOJ2729:[HNOI2012]排队(组合数学)的更多相关文章
- 【bzoj2729】[HNOI2012]排队 组合数学+高精度
题目描述 某中学有 n 名男同学,m 名女同学和两名老师要排队参加体检.他们排成一条直线,并且任意两名女同学不能相邻,两名老师也不能相邻,那么一共有多少种排法呢?(注意:任意两个人都是不同的) 输入 ...
- [BZOJ2729]:[HNOI2012]排队(组合数学)
题目传送门 题目描述 某中学有n名男同学,m名女同学和两名老师要排队参加体检.他们排成一条直线,并且任意两名女同学不能相邻,两名老师也不能相邻,那么一共有多少种排法呢?(注意:任意两个人都是不同的) ...
- BZOJ2729 [HNOI2012]排队 【高精 + 组合数学】
题目链接 BZOJ2729 题解 高考数学题... 我们先把老师看做男生,女生插空站 如果两个老师相邻,我们把他们看做一个男生,女生插空站 对于\(n\)个男生\(m\)个女生的方案数: \[n!m! ...
- BZOJ2729 HNOI2012排队(组合数学+高精度)
组合入门题.高精度入门题. #include<iostream> #include<cstdio> #include<cstdlib> #include<cs ...
- bzoj2729 [HNOI2012]排队
组合数学,推一下式子,并不难推. java代码 import java.io.*; import java.math.BigInteger; import java.util.*; public cl ...
- [bzoj2729][HNOI2012]排队 题解 (排列组合 高精)
Description 某中学有 n 名男同学,m 名女同学和两名老师要排队参加体检.他们排成一条直线,并且任意两名女同学不能相邻,两名老师也不能相邻,那么一共有多少种排法呢?(注意:任意两个人都是不 ...
- 【BZOJ2729】[HNOI2012]排队 组合数
[BZOJ2729][HNOI2012]排队 Description 某中学有 n 名男同学,m 名女同学和两名老师要排队参加体检.他们排成一条直线,并且任意两名女同学不能相邻,两名老师也不能相邻,那 ...
- bzoj 2729: [HNOI2012]排队
2729: [HNOI2012]排队 Time Limit: 10 Sec Memory Limit: 128 MB Description 某中学有 n 名男同学,m 名女同学和两名老师要排队参加体 ...
- 2729: [HNOI2012]排队
2729: [HNOI2012]排队 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 957 Solved: 449[Submit][Status] ...
随机推荐
- 安装SQL SEVER 2017 express 轻量入门级软件 安装教程
1. 首先 打开网址 https://www.microsoft.com/zh-tw/sql-server/sql-server-downloads 点击下载 , 下载完成之后, 点开安装 ...
- 纠错帖:Zuul & Spring Cloud Gateway & Linkerd性能对比 (转载)
纠错帖:Zuul & Spring Cloud Gateway & Linkerd性能对比 Spring Cloud Spring Cloud Spring Cloud Gatew ...
- 在php中怎么利用js把参数传递给弹窗
1.在php页面中经常用到把参数传递给弹窗页面,在弹窗页面中操作 2.两种方式,截图为一种 3.最常见的就是利用hideen隐藏域,点击按钮的时候把要传递的参数值传递给隐藏域,需要的时候在弹窗中获取. ...
- Code Signal_练习题_isLucky
Ticket numbers usually consist of an even number of digits. A ticket number is considered lucky if t ...
- vue 面试时需要准备的知识点
前端火热的框架层出不穷,作为码农的我们,依旧需要去学习,去探索新的问题,学习新技术,其实就是为了写一手好的,自认为是高质量的代码.今天主要分享一下前端最火的框架vue,也是我比较喜欢的框架. vue上 ...
- 润乾报表如何使用Echarts
1. 润乾报表中使用Echarts统计图的步骤 2. 报表中添加echarts2统计图 选中需要设为统计图的单元格,点击 报表-第三方图形 菜单项,或者右键菜单-第三方图形,在图形编 ...
- Android保持屏幕常亮
Android保持屏幕常亮,PowerManager.WakeLock的使用 package com.hebaijun.wakelock; import android.app.Activi ...
- sql 字段别名里包含特殊字符
select ename employee.name from emp; 在数据库查询时,如果列名的别名里特殊符号,报错. select ename 'employee.name' from emp; ...
- LeetCode题解之Peak Index in a MountainArray
1 题目描述 2.问题分析 直接从后向前遍历,找到 A[i] > A[i-1] 即可. 3.代码 int peakIndexInMountainArray(vector<int>&a ...
- 教你如何获取ipa包中的开发文件
教你如何获取ipa包中的开发文件 1. 从iTunes获取到ipa包 2. 修改ipa包然后获取里面的开发文件