欢迎来到天天文库
浏览记录
ID:15677844
大小:220.56 KB
页数:112页
时间:2018-08-04
《蓝桥杯决赛编程题汇总(含答案)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、一.结果填空题。1.求最大公约数//辗转相除,求两个数的最大公约数publicstaticintgcd(intn,intm){if(n==0)returnm;returngcd(m%n,n);}//最小公倍数=n*m/gcd(n,m)publicstaticintgbs(intn,intm){returnn*m/gcd(n,m);}2.a的n次幂publicstaticintf(inta,intn){intx=1;for(inti=0;i2、b%p)//(a*b)%p=((a%p)*(b%p))%p//a的n次幂对p取模publicstaticintf2(inta,intn,intp){intx=1;for(inti=0;i3、n){intN=1000*1000*10;byte[]a=newbyte[N];for(inti=2;i4、),有多少种取法?算法实现:publicclassTest_01{//在n个球中,任意去除m个(不放回),有多少种取法?publicstaticinttest_01(intn,intm){//出口设计。。。if(n5、oidmain(String[]args){intk=test_01(10,3);System.out.println(k);}}5.用递归实现,求n的阶乘,算法实现:publicclassTest_01{//用递归实现,求n的阶乘,publicstaticintgetNum(intn){if(n==16、7、n==0){returnn;}else{returnn*getNum(n-1);}}publicstaticvoidmain(String[]args){System.out.println(getNum(3));}}6.求8、n个元素的全排列publicclassTest_02{//求n个元素的全排列//abcacbbacbcacabcba/***规律:每个元素都可以放到首位,然后排放剩余的元素*///打印所有的全排列publicstaticvoidmain(String[]args){char[]data="ABC".toCharArray();f(data,0);}//k:当前的交换位置(关注点),与其后的元素交换privatestaticvoidf(char[]data,intk){if(k==data.length-1){for(inti=9、0;i10、可解,优化publicstaticvoidmain(String[]args){intk=f("abc","xbacd");System.out.println(k);}privatestaticintf(Strings1,Strings2){if(s1.length()==
2、b%p)//(a*b)%p=((a%p)*(b%p))%p//a的n次幂对p取模publicstaticintf2(inta,intn,intp){intx=1;for(inti=0;i3、n){intN=1000*1000*10;byte[]a=newbyte[N];for(inti=2;i4、),有多少种取法?算法实现:publicclassTest_01{//在n个球中,任意去除m个(不放回),有多少种取法?publicstaticinttest_01(intn,intm){//出口设计。。。if(n5、oidmain(String[]args){intk=test_01(10,3);System.out.println(k);}}5.用递归实现,求n的阶乘,算法实现:publicclassTest_01{//用递归实现,求n的阶乘,publicstaticintgetNum(intn){if(n==16、7、n==0){returnn;}else{returnn*getNum(n-1);}}publicstaticvoidmain(String[]args){System.out.println(getNum(3));}}6.求8、n个元素的全排列publicclassTest_02{//求n个元素的全排列//abcacbbacbcacabcba/***规律:每个元素都可以放到首位,然后排放剩余的元素*///打印所有的全排列publicstaticvoidmain(String[]args){char[]data="ABC".toCharArray();f(data,0);}//k:当前的交换位置(关注点),与其后的元素交换privatestaticvoidf(char[]data,intk){if(k==data.length-1){for(inti=9、0;i10、可解,优化publicstaticvoidmain(String[]args){intk=f("abc","xbacd");System.out.println(k);}privatestaticintf(Strings1,Strings2){if(s1.length()==
3、n){intN=1000*1000*10;byte[]a=newbyte[N];for(inti=2;i4、),有多少种取法?算法实现:publicclassTest_01{//在n个球中,任意去除m个(不放回),有多少种取法?publicstaticinttest_01(intn,intm){//出口设计。。。if(n5、oidmain(String[]args){intk=test_01(10,3);System.out.println(k);}}5.用递归实现,求n的阶乘,算法实现:publicclassTest_01{//用递归实现,求n的阶乘,publicstaticintgetNum(intn){if(n==16、7、n==0){returnn;}else{returnn*getNum(n-1);}}publicstaticvoidmain(String[]args){System.out.println(getNum(3));}}6.求8、n个元素的全排列publicclassTest_02{//求n个元素的全排列//abcacbbacbcacabcba/***规律:每个元素都可以放到首位,然后排放剩余的元素*///打印所有的全排列publicstaticvoidmain(String[]args){char[]data="ABC".toCharArray();f(data,0);}//k:当前的交换位置(关注点),与其后的元素交换privatestaticvoidf(char[]data,intk){if(k==data.length-1){for(inti=9、0;i10、可解,优化publicstaticvoidmain(String[]args){intk=f("abc","xbacd");System.out.println(k);}privatestaticintf(Strings1,Strings2){if(s1.length()==
4、),有多少种取法?算法实现:publicclassTest_01{//在n个球中,任意去除m个(不放回),有多少种取法?publicstaticinttest_01(intn,intm){//出口设计。。。if(n5、oidmain(String[]args){intk=test_01(10,3);System.out.println(k);}}5.用递归实现,求n的阶乘,算法实现:publicclassTest_01{//用递归实现,求n的阶乘,publicstaticintgetNum(intn){if(n==16、7、n==0){returnn;}else{returnn*getNum(n-1);}}publicstaticvoidmain(String[]args){System.out.println(getNum(3));}}6.求8、n个元素的全排列publicclassTest_02{//求n个元素的全排列//abcacbbacbcacabcba/***规律:每个元素都可以放到首位,然后排放剩余的元素*///打印所有的全排列publicstaticvoidmain(String[]args){char[]data="ABC".toCharArray();f(data,0);}//k:当前的交换位置(关注点),与其后的元素交换privatestaticvoidf(char[]data,intk){if(k==data.length-1){for(inti=9、0;i10、可解,优化publicstaticvoidmain(String[]args){intk=f("abc","xbacd");System.out.println(k);}privatestaticintf(Strings1,Strings2){if(s1.length()==
5、oidmain(String[]args){intk=test_01(10,3);System.out.println(k);}}5.用递归实现,求n的阶乘,算法实现:publicclassTest_01{//用递归实现,求n的阶乘,publicstaticintgetNum(intn){if(n==1
6、
7、n==0){returnn;}else{returnn*getNum(n-1);}}publicstaticvoidmain(String[]args){System.out.println(getNum(3));}}6.求
8、n个元素的全排列publicclassTest_02{//求n个元素的全排列//abcacbbacbcacabcba/***规律:每个元素都可以放到首位,然后排放剩余的元素*///打印所有的全排列publicstaticvoidmain(String[]args){char[]data="ABC".toCharArray();f(data,0);}//k:当前的交换位置(关注点),与其后的元素交换privatestaticvoidf(char[]data,intk){if(k==data.length-1){for(inti=
9、0;i10、可解,优化publicstaticvoidmain(String[]args){intk=f("abc","xbacd");System.out.println(k);}privatestaticintf(Strings1,Strings2){if(s1.length()==
10、可解,优化publicstaticvoidmain(String[]args){intk=f("abc","xbacd");System.out.println(k);}privatestaticintf(Strings1,Strings2){if(s1.length()==
此文档下载收益归作者所有