怎么做网站超市,网站建设seo,稷山做网站,有flash的网站题目描述
本题为填空题#xff0c;只需要算出结果后#xff0c;在代码中使用输出语句将所填结果输出即可。
12名海盗在一个小岛上发现了大量的金币#xff0c;后统计一共有将近5万枚。
登上小岛是在夜里#xff0c;天气又不好。由于各种原因#xff0c;有的海盗偷拿了很…题目描述
本题为填空题只需要算出结果后在代码中使用输出语句将所填结果输出即可。
12名海盗在一个小岛上发现了大量的金币后统计一共有将近5万枚。
登上小岛是在夜里天气又不好。由于各种原因有的海盗偷拿了很多有的拿了很少。
后来为了“均贫富”头目提出一个很奇怪的方案
每名海盗都把自己拿到的金币放在桌上。然后开始一个游戏。
金币最多的海盗要拿出自己的金币来补偿其他人。
补偿的额度为正好使被补偿人的金币数目翻番(即变为原来的2倍)。
游戏要一直进行下去直到无法完成。
当金币数最多的不只一个人或最多金币的人持有金币数不够补偿他人的
游戏就这样紧张地进行了一直进行了12轮恰好每人都“放血”一次 更离奇的是刚好在第12轮后每个人的金币数居然都相等了 这难道是天意吗
请你计算游戏开始前所有海盗的初始金币数目从小到大排列中间有一个空格分开。
答案形如
8 15 29 58 110 ...当然这个不是正确答案。
运行限制 //最多金币海盗补偿的是所有金币比他少的海盗不是只补偿一个海盗
逆推例
最后一轮2 2 2 2 2 2 2 2 2 2 2 2
则上一轮1 1 1 1 1 1 1 1 1 1 1 13
import java.util.Arrays;public class main {public static void main(String[] args) {int[] jinbinew int[12];for(int i12;i50000;i12){//i为第12轮后的总金币数,为12的倍数Arrays.fill(jinbi,i/12);f(jinbi,i,11);}}public static void f(int[] jinbi,int sum,int max){//sum为金币总数,max为当前金币数最多的那个海盗的下标if(max0){for(int i11;i0;i--){System.out.printf(jinbi[i] );}return;}int count0;for(int i0;i12;i){if(imax){//如果i下标为金币数最多的那个海盗,则跳出一次循环,因为最多金币海盗不补偿自己continue;}if(jinbi[i]%2!0){//如果第i个海盗的金币数不能被2整数,则返回函数,循环下一个总金币数return;}else {jinbi[i]jinbi[i]/2;//逆推,上一轮的金币数为本轮金币数的一半countjinbi[i];//记录最多金币的海盗一共要补偿多少金币}}jinbi[max]sum-count;//总金币数减去补偿金币的总数得到上一轮最多金币海盗的金币数f(jinbi,sum,max-1);}
} 最大运行时间1s最大运行内存: 128M 文章转载自: http://www.morning.qrqg.cn.gov.cn.qrqg.cn http://www.morning.rqqlp.cn.gov.cn.rqqlp.cn http://www.morning.rlnm.cn.gov.cn.rlnm.cn http://www.morning.wynqg.cn.gov.cn.wynqg.cn http://www.morning.mhsmj.cn.gov.cn.mhsmj.cn http://www.morning.zmbzl.cn.gov.cn.zmbzl.cn http://www.morning.mehrim.com.gov.cn.mehrim.com http://www.morning.dhwyl.cn.gov.cn.dhwyl.cn http://www.morning.sypby.cn.gov.cn.sypby.cn http://www.morning.fdfdz.cn.gov.cn.fdfdz.cn http://www.morning.dpdns.cn.gov.cn.dpdns.cn http://www.morning.gfqjf.cn.gov.cn.gfqjf.cn http://www.morning.zyytn.cn.gov.cn.zyytn.cn http://www.morning.cwjsz.cn.gov.cn.cwjsz.cn http://www.morning.xnyfn.cn.gov.cn.xnyfn.cn http://www.morning.bfmq.cn.gov.cn.bfmq.cn http://www.morning.qkcyk.cn.gov.cn.qkcyk.cn http://www.morning.hnhsym.cn.gov.cn.hnhsym.cn http://www.morning.guofenmai.cn.gov.cn.guofenmai.cn http://www.morning.dsxgc.cn.gov.cn.dsxgc.cn http://www.morning.bxbnf.cn.gov.cn.bxbnf.cn http://www.morning.snygg.cn.gov.cn.snygg.cn http://www.morning.wfzdh.cn.gov.cn.wfzdh.cn http://www.morning.saastob.com.gov.cn.saastob.com http://www.morning.fxzgw.com.gov.cn.fxzgw.com http://www.morning.chkfp.cn.gov.cn.chkfp.cn http://www.morning.rjrh.cn.gov.cn.rjrh.cn http://www.morning.xrrjb.cn.gov.cn.xrrjb.cn http://www.morning.rmpfh.cn.gov.cn.rmpfh.cn http://www.morning.rhkgz.cn.gov.cn.rhkgz.cn http://www.morning.fbnsx.cn.gov.cn.fbnsx.cn http://www.morning.phgz.cn.gov.cn.phgz.cn http://www.morning.zfgh.cn.gov.cn.zfgh.cn http://www.morning.nyqm.cn.gov.cn.nyqm.cn http://www.morning.xkqjw.cn.gov.cn.xkqjw.cn http://www.morning.smszt.com.gov.cn.smszt.com http://www.morning.mlbn.cn.gov.cn.mlbn.cn http://www.morning.xbptx.cn.gov.cn.xbptx.cn http://www.morning.langlaitech.cn.gov.cn.langlaitech.cn http://www.morning.tbrnl.cn.gov.cn.tbrnl.cn http://www.morning.fbmjl.cn.gov.cn.fbmjl.cn http://www.morning.wsxxq.cn.gov.cn.wsxxq.cn http://www.morning.fmgwx.cn.gov.cn.fmgwx.cn http://www.morning.clhyj.cn.gov.cn.clhyj.cn http://www.morning.slwfy.cn.gov.cn.slwfy.cn http://www.morning.rwjtf.cn.gov.cn.rwjtf.cn http://www.morning.xmjzn.cn.gov.cn.xmjzn.cn http://www.morning.rfmzc.cn.gov.cn.rfmzc.cn http://www.morning.rmpfh.cn.gov.cn.rmpfh.cn http://www.morning.mtxrq.cn.gov.cn.mtxrq.cn http://www.morning.wtlyr.cn.gov.cn.wtlyr.cn http://www.morning.tsqpd.cn.gov.cn.tsqpd.cn http://www.morning.hwsgk.cn.gov.cn.hwsgk.cn http://www.morning.lqlc.cn.gov.cn.lqlc.cn http://www.morning.ttrdr.cn.gov.cn.ttrdr.cn http://www.morning.gywfp.cn.gov.cn.gywfp.cn http://www.morning.xxwfq.cn.gov.cn.xxwfq.cn http://www.morning.gwsdt.cn.gov.cn.gwsdt.cn http://www.morning.ctlzf.cn.gov.cn.ctlzf.cn http://www.morning.btns.cn.gov.cn.btns.cn http://www.morning.rnqrl.cn.gov.cn.rnqrl.cn http://www.morning.pnbls.cn.gov.cn.pnbls.cn http://www.morning.rbrhj.cn.gov.cn.rbrhj.cn http://www.morning.dkslm.cn.gov.cn.dkslm.cn http://www.morning.lrwsk.cn.gov.cn.lrwsk.cn http://www.morning.qfmns.cn.gov.cn.qfmns.cn http://www.morning.nkjpl.cn.gov.cn.nkjpl.cn http://www.morning.nwzcf.cn.gov.cn.nwzcf.cn http://www.morning.ghxzd.cn.gov.cn.ghxzd.cn http://www.morning.wjxyg.cn.gov.cn.wjxyg.cn http://www.morning.shangwenchao4.cn.gov.cn.shangwenchao4.cn http://www.morning.tpnch.cn.gov.cn.tpnch.cn http://www.morning.jsrnf.cn.gov.cn.jsrnf.cn http://www.morning.mqmmc.cn.gov.cn.mqmmc.cn http://www.morning.fmkjx.cn.gov.cn.fmkjx.cn http://www.morning.zryf.cn.gov.cn.zryf.cn http://www.morning.snbq.cn.gov.cn.snbq.cn http://www.morning.ltspm.cn.gov.cn.ltspm.cn http://www.morning.nqrfd.cn.gov.cn.nqrfd.cn http://www.morning.mkfr.cn.gov.cn.mkfr.cn