思路:高精度\((what)\)

提交:2次(后来发现有种更快的写法)

题解:

设\(n>m\),那么显然答案为\(C(n,m)\),相当于只能放\(m\)个棋子,可以在\(n\)列中选任意不同的\(m\)列上。

刚开始是这种解法:(\(3560ms\))

  1. #include<cstdio>
  2. #include<iostream>
  3. #define ull unsigned long long
  4. #define ll long long
  5. #define R register int
  6. using namespace std;
  7. #define pause (for(R i=1;i<=10000000000;++i))
  8. #define In freopen("NOIPAK++.in","r",stdin)
  9. #define Out freopen("out.out","w",stdout)
  10. namespace Fread {
  11. static char B[1<<15],*S=B,*D=B;
  12. #ifndef JACK
  13. #define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++)
  14. #endif
  15. inline int g() {
  16. R ret=0,fix=1; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-1:fix;
  17. if(ch==EOF) return EOF; do ret=ret*10+(ch^48); while(isdigit(ch=getchar())); return ret*fix;
  18. } inline bool isempty(const char& ch) {return (ch<=36||ch>=127);}
  19. inline void gs(char* s) {
  20. register char ch; while(isempty(ch=getchar()));
  21. do *s++=ch; while(!isempty(ch=getchar()));
  22. }
  23. } using Fread::g; using Fread::gs;
  24. namespace Luitaryi {
  25. const int N=1000010;
  26. const ll B=1E+10;
  27. int n,m,sz=1,c[N];
  28. ll a[7];
  29. inline void inc(int x) {for(R i=2;i*i<=x;++i) while(x%i==0) x/=i,++c[i]; if(x&&x!=1) ++c[x];}
  30. inline void dec(int x) {for(R i=2;i*i<=x;++i) while(x%i==0) x/=i,--c[i]; if(x&&x!=1) --c[x];}
  31. inline void mul(int x) { register ll tmp=0;
  32. for(R i=1;i<=sz;++i) {
  33. a[i]*=x,a[i]+=tmp;
  34. tmp=a[i]/B,a[i]%=B;
  35. } if(tmp) ++sz,a[sz]=tmp; if(sz>5) sz=5;
  36. }
  37. inline void calc() {for(R i=2;i<=n;++i) while(c[i]) mul(i),--c[i];}
  38. inline void main() {
  39. n=g(),m=g(); m>n?swap(n,m):void(0);
  40. if(m==n) return (void)printf("1\n");
  41. for(R i=n;i>m;--i) inc(i);
  42. for(R i=2;i<=n-m;++i) dec(i);
  43. a[1]=1; calc(); printf("%lld",a[sz]); for(R i=sz-1;i;--i) printf("%010lld",a[i]);
  44. }
  45. }
  46. signed main() {
  47. Luitaryi::main(); return 0;
  48. }

后来看到有这样的:(快的一批\(260ms\))

  1. #include<cstdio>
  2. #include<iostream>
  3. #define ull unsigned long long
  4. #define ll long long
  5. #define R register int
  6. using namespace std;
  7. #define pause (for(R i=1;i<=10000000000;++i))
  8. #define In freopen("NOIPAK++.in","r",stdin)
  9. #define Out freopen("out.out","w",stdout)
  10. namespace Fread {
  11. static char B[1<<15],*S=B,*D=B;
  12. #ifndef JACK
  13. #define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++)
  14. #endif
  15. inline int g() {
  16. R ret=0,fix=1; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-1:fix;
  17. if(ch==EOF) return EOF; do ret=ret*10+(ch^48); while(isdigit(ch=getchar())); return ret*fix;
  18. }
  19. } using Fread::g;
  20. namespace Luitaryi {
  21. const int N=1000010;
  22. const ll B=1E+10;
  23. int n,m,sz=1,cnt,c[N],mnd[N],pri[N>>1];
  24. ll a[7];
  25. inline void PRE(int n) {
  26. for(R i=2;i<=n;++i) {
  27. if(!mnd[i]) mnd[i]=i,pri[++cnt]=i;
  28. for(R j=1;j<=cnt&&i*pri[j]<=n;++j) {
  29. mnd[i*pri[j]]=pri[j];
  30. if(i%pri[j]==0) break;
  31. }
  32. }
  33. }
  34. inline void inc(int x) {while(x>1) ++c[mnd[x]],x/=mnd[x];}
  35. inline void dec(int x) {while(x>1) --c[mnd[x]],x/=mnd[x];}
  36. inline void mul(int x) { register ll tmp=0;
  37. for(R i=1;i<=sz;++i) {
  38. a[i]*=x,a[i]+=tmp;
  39. a[i]>=B?tmp=a[i]/B,a[i]%=B:tmp=0;
  40. } if(tmp) a[++sz]=tmp; if(sz>5) sz=5;
  41. }
  42. inline void calc() {for(R i=1;i<=cnt;++i) while(c[pri[i]]) mul(pri[i]),--c[pri[i]];}
  43. inline void main() {
  44. n=g(),m=g(); m>n?swap(n,m):void(0); PRE(n);
  45. if(m==n) return (void)printf("1\n");
  46. for(R i=n;i>m;--i) inc(i);
  47. for(R i=2;i<=n-m;++i) dec(i);
  48. a[1]=1; calc(); printf("%lld",a[sz]); for(R i=sz-1;i;--i) printf("%010lld",a[i]);
  49. }
  50. }
  51. signed main() {
  52. Luitaryi::main(); return 0;
  53. }

\(zz\)忽然感受到我数学白学了


2019.07.23

BZOJ 4807 車 组合数学的更多相关文章

  1. bzoj 4807: 車【组合数+高精+线性筛】

    设n>m,答案是\( C_n^m \),然后高精就行了 具体做法是先把指数筛出来,然后对每个数因数分解,记录质因子个数,最后被除数减去除数质因子个数,把剩下的质因子乘起来就行了 #include ...

  2. BZOJ4807:車(组合数学,高精度)

    Description 众所周知,車是中国象棋中最厉害的一子之一,它能吃到同一行或同一列中的其他棋子.車跟車显然不能在一起打起来,于是rly一天又借来了许多许多的車在棋盘上摆了起来……他想知道,在N× ...

  3. BZOJ 3997: [TJOI2015]组合数学 [偏序关系 DP]

    3997: [TJOI2015]组合数学 题意:\(n*m:\ n \le 1000\)网格图,每个格子有权值.每次从左上角出发,只能向下或右走.经过一个格子权值-1.至少从左上角出发几次所有权值为0 ...

  4. bzoj 3907: 网格 组合数学

    3907: 网格 Time Limit: 1 Sec  Memory Limit: 256 MBSubmit: 13  Solved: 7[Submit][Status][Discuss] Descr ...

  5. bzoj 3997 [TJOI2015]组合数学(DP)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3997 [题意] 给定一个nm的长方形,每次只能使经过格子权值减1,每次只能向右向下,问 ...

  6. BZOJ 3997 TJOI2015 组合数学

    分析一下样例就可以知道,求的实际上是从左下角到右上角的最长路 因为对于任意不在这个最长路的上的点,都可以通过经过最长路上的点的路径将这个点的价值减光 (可以用反证法证明) 之后就是一个非常NOIP的D ...

  7. BZOJ 1008 越狱 (组合数学)

    题解:正难则反,从总数中减去全部相邻不相同的数目就是答案,n*(n-1)^(m-1):第一个房间有n中染色方案,剩下m-1个房间均只有n-1种染色方案,用总数减就是答案. #include <c ...

  8. BZOJ 2142 礼物 组合数学 CRT 中国剩余定理

    2142: 礼物 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 1450  Solved: 593[Submit][Status][Discuss] ...

  9. BZOJ 1008 越狱 组合数学

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1008 题目大意: 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗 ...

随机推荐

  1. 关于php发送邮件(PHPmailer)的傻瓜式操作

    首先打开QQ邮箱(此处我们以QQ邮箱为例) 点击设置里面的账户开启pop3和smtp(此处需要用到绑定的手机号进行短信或QQ安全中心动态码进行验证) 接着复制以下email代码 //发送邮件 publ ...

  2. QT聊天室--重大bug

    发送qqqqqqqqqqqqqqqqqqqqqqq: 发送test

  3. python __enter__ 与 __exit__的作用,以及与 with 语句的关系(转)

    https://blog.csdn.net/xc_zhou/article/details/80810111 python __enter__ 与 __exit__的作用,以及与 with 语句的关系

  4. List 集合的常用方法总结

    @org.junit.Test public void testListToCompare() { List<String> list1 = new ArrayList<>() ...

  5. cnn健康增胖和调理好身体

    吃不胖,其实大部分情况是消化系统不好,大部分食物都没有被身体吸收就被排掉了. 1,改善肠胃消化功能: 每天早上一杯全脂鲜牛奶(或者羊奶), 每天晚上一杯酸奶 ps:白天和鲜牛奶可以激发肠胃的消化能力. ...

  6. Kong命令(二)service

    service介绍: service 是声明了一组name.host.port.protocol等配置的函数.可以绑定route.upstream上下游服务.并且对于route.upstream可以绑 ...

  7. springboot2.0介绍1

    SpringBoot 一. Spring介绍 1.1.SpringBoot简介 在您第1次接触和学习Spring框架的时候,是否因为其繁杂的配置而退却了?在你第n次使用Spring框架的时候,是否觉得 ...

  8. Go微服务 grpc的简单使用

    作者:薇文文链接:https://www.jianshu.com/p/20ed82218163来源:简书 准备工作 先安装Protobuf 编译器 protoc,下载地址:https://github ...

  9. sql server存储过程返回数据只有一个字符

    SqlParameter[] param = { new SqlParameter("@shopId",shopId), new SqlParameter("@newSh ...

  10. Windows服务 + Quartz.NET

    服务基础 安装管理员打开cmd cd C:\Windows\Microsoft.NET\Framework\v4.0.30319 InstallUtil.exe Path_WinSvc.exe 或者 ...