hdu 6129-推理
来源:互联网 发布:vod网络媒体播放器 编辑:程序博客网 时间:2024/05/20 16:11
题目链接:点击打开链接
题解思路:依题意模拟一下画出一个这样的三角形你会发现,例如以n=4,m = 1为例
1
2 1
3 2 1
4 3 2 1
第n行第k列表示 第k个数 对 第n个数贡献的次数
斜着看以最外层为第一层,当然第一层都是一,那么第二层就是C(m,1),第三层就是C(m+1,2),以此类推。那么我们又有公式C(m,n) = m/n*C(m-1,n-1),所以每次记住上个状态内含有二的几次方,顺便把n和m也一起求,然后看他们二的个数是不是相等,如果是贡献就为一,就暴力更新。
代码:
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#define inf 0x3f3f3f3fusing namespace std;const int mx = 2e5+10,mod = 1e9+7;typedef long long ll;int n,m,a[mx],b[mx];int main(){ int t; scanf("%d",&t); while(t--){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%d",a+i), b[i] = a[i]; for(int i=1,now=0;i<n;i++,m++){ int po = m, to = i, cnt1 = 0,cnt2 = 0; while(po%2==0){ po /= 2; cnt1++; } while(to%2==0){ to /= 2; cnt2++; } if(now+cnt1==cnt2){ for(int j=1,k=i+1;k<=n;k++,j++) a[k] ^= b[j]; } now = now+cnt1-cnt2; } for(int i=1;i<n;i++) printf("%d ",a[i]); printf("%d\n",a[n]); } return 0;}
阅读全文
0 0
- hdu 6129-推理
- hdu 5399(数学推理)
- HDU 4764 Stone(博弈+推理)
- hdu 1124 Factorial(数论:推理)
- HDU 4925 Apple Tree(推理)
- hdu 5014 思维题/推理
- 推理
- HDU 4473 HDOJ Exam (推理,5级)
- HDU 4869 Turn the pokers(推理)
- HDU 4927 Series 1(推理+大数)
- HDU 4932 Miaomiao's Geometry(推理)
- hdu 4611 Balls Rearrangement(数学:推理+模拟)
- hdu 4970 Just Random(数学:推理)
- HDU 2524--矩形A + B【推理 && 水题】
- hdu 2608 0 or 1(数论推理)
- hdu 1014 Uniform Generator(数论推理)
- Hdu 5873 Football Games 推理(XJBC
- Hdu 5400 Arithmetic Sequence 数学推理
- 绝对强大的三个linux指令: ar, nm, objdump
- docker详解
- 读入优化
- JavaWeb(2)_myEclipse_端口被占用
- C Primer Plus 第五章
- hdu 6129-推理
- 浅谈boostrap轮播插件原理
- oracle database 12c Release 2-Managing Undo 翻译(第二章节)
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- HDU 3416 Marriage Match IV(最短路+最大流(sap))
- MySQL入门学习
- 模板中使用函数的方法-thinkphp
- Application 中报第三方服务,java.lang.NoClassDefFoundError 解决的方案
- nginx 日志pv uv统计