首页 > 其他分享 >BZOJ 4807(車-高精度)

BZOJ 4807(車-高精度)

时间:2022-10-24 18:02:47浏览次数:45  
标签:BigInteger return 高精度 int ll 4807 MOD BZOJ define


Description
众所周知,車是中国象棋中最厉害的一子之一,它能吃到同一行或同一列中的其他棋子。車跟車显然不能在一起打
起来,于是rly一天又借来了许多许多的車在棋盘上摆了起来……他想知道,在N×M的矩形方格中摆最多个数的車
使其互不吃到的情况下方案数有几种。但是,由于上次摆炮摆得实在太累,他为了偷懒,打算增加一个条件:对于
任何一个車A,如果有其他一个車B在它的上面(車B行号小于車A),那么車A必须在車B的右边(車A列号大于車B)

棋子都是相同的。

Input
一行,两个正整数N和M。
N<=1000000,M<=1000000

Output
一行,输出方案数的末尾50位(不足则直接输出)。

Sample Input
2 2
Sample Output
1
HINT

Source

By FancyCoder

答案是C(max(n,m),min(n,m))

#include<bits/stdc++.h> 
using namespace std;
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma
#define
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define
int p[MAXN],tot,mn[MAXN];
bool b[MAXN]={0};
void make_prime(int n)
{
tot=0;
Fork(i,2,n)
{
if (!b[i]) p[++tot]=i,mn[i]=i;
For(j,tot)
{
if (i*p[j]>n) break;
b[i*p[j]]=1;mn[i*p[j]]=p[j];
if (i%p[j]==0) break;
}
}
}
int cnt[MAXN]={0};
void modify(int x,int c) {
while(x!=1) {
cnt[mn[x]]+=c;
x/=mn[x];
}
}

#define
struct BigInteger {
int n;
int a[MAXN];
enum {MOD=10};
BigInteger() {
MEM(a) a[0]=1;
}
int& operator [] (int p) {return a[p];}
const int& operator [] (int p) const {return a[p];}
BigInteger(int x) {
a[0]=1;
a[1]=x%MOD;
x/=MOD;
while(x) a[++a[0]]=x%MOD,x/=MOD;
}
friend BigInteger operator*(BigInteger a,BigInteger b) {
BigInteger c;
c[0]=a[0]+b[0];
For(i,a[0])
For(j,b[0]){
c[i+j-1]+=a[i]*b[j], c[i+j]+=c[i+j-1]/MOD, c[i+j-1]%=MOD;
}
if (c[c[0]] == 0 ) c[0]--;
c[0]=min(c[0],50);
return c;
}
void print() {
while (a[0]&&a[a[0]] == 0 ) a[0]--;
ForD(i,a[0]) {
if(i==a[0]) printf("%d",a[i]);
else printf("%d",a[i]);
}
}
};

int main()
{
// freopen("bzoj4807.in","r",stdin);
// freopen(".out","w",stdout);
int n=read(),m=read();
if (n<m) swap(n,m);
make_prime(1000000);
Fork(i,m+1,n) modify(i,1);
For(i,n-m) modify(i,-1);
BigInteger a(1);
For(i,n)
For(j,cnt[i])
a=a*i;
a.print();
return 0;
}


标签:BigInteger,return,高精度,int,ll,4807,MOD,BZOJ,define
From: https://blog.51cto.com/u_15724837/5790757

相关文章

  • BZOJ 4805(欧拉函数求和-杜教筛)
    Description给出一个数字N,求sigma(phi(i)),1<=i<=NInput正整数N。N<=2*10^9Output输出答案。SampleInput10SampleOutput32HINT杜教筛入门#include<bits/stdc++......
  • BZOJ 4810([Ynoi2017]由乃的玉米田-莫队)
    Description由乃在自己的农田边散步,她突然发现田里的一排玉米非常的不美。这排玉米一共有N株,它们的高度参差不齐。由乃认为玉米田不美,所以她决定出个数据结构题这个题是这......
  • BZOJ 3503([Cqoi2014]和谐矩阵-gauss消元)
    Description我们称一个由0和1组成的矩阵是和谐的,当且仅当每个元素都有偶数个相邻的1。一个元素相邻的元素包括它本身,及他上下左右的4个元素(如果存在)。给定矩阵的行数和......
  • 基于八方向的sobel算子高精度边缘提取检测算法matlab仿真
    目录一、理论基础1.1传统算法概述1.28方向sobel算法二、核心程序三、仿真测试结果作者ID:fpga和matlabCSDN主页:https://blog.csdn.net/ccsss22?type=blog擅长技术:1......
  • 高精度NTP网络时钟系统(NTP时间服务器)技术参数说明
    高精度NTP网络时钟系统(NTP时间服务器)技术参数说明高精度NTP网络时钟系统(NTP时间服务器)技术参数说明京准电子科技官微——ahjzsz简介京准电子科技有限公司研制开发的标......
  • bzoj 2301: [HAOI2011]Problem b mobius反演 RE
    ​​http://www.lydsy.com/JudgeOnline/problem.php?id=2301​​设f(i)为在区间[1,n]和区间[1,m]中,gcd(x,y)=i的个数。设F(i)为在区间[1,n]和区间[1,m]中,gcd(x,y)%......
  • 高精度加法
    vector<int>add(vector<int>&A,vector<int>&B){if(A.size()<B.size())returnadd(B,A);vector<int>C;intt=0;for(inti=0;i<A.......
  • 高精度除法
    //A/b=C...r,A>=0,b>0vector<int>div(vector<int>&A,intb,int&r){vector<int>C;r=0;for(inti=A.size()-1;i>=0;i--)......
  • 高精度乘法
    //C=A*b,A>=0,b>=0vector<int>mul(vector<int>&A,intb){vector<int>C;intt=0;for(inti=0;i<A.size()||t;i++){......
  • 高精度减法
    //C=A-B,满足A>=B,A>=0,B>=0vector<int>sub(vector<int>&A,vector<int>&B){vector<int>C;for(inti=0,t=0;i<A.size();i++)......