APP客户端网站建设,凡科门店通怎么样,网站建设 排名,怎么改wordpress字体大小竞赛总览
CSDN 编程竞赛三十二期#xff1a;比赛详情 (csdn.net)
竞赛题解
题目1、传奇霸业
传奇霸业#xff0c;是兄弟就来干。小春#xff08;HP为a#xff09;遇到了一只黄金哥布林#xff08;HP为x#xff09;。小春每次能对哥布林造成b点伤害#xff0c;哥布林…竞赛总览
CSDN 编程竞赛三十二期比赛详情 (csdn.net)
竞赛题解
题目1、传奇霸业
传奇霸业是兄弟就来干。小春HP为a遇到了一只黄金哥布林HP为x。小春每次能对哥布林造成b点伤害哥布林每次能对小春造成y点伤害。作为玩家的小春怎么可能随便让哥布林打死呢他有治疗神药每次能恢复c点HP。HP无上限。小春需要操作多少次治疗攻击才能打死哥布林
#include cstdiostruct role {int hp;int attack;
};int main () {int a, b, c, x, y;scanf (%d %d %d %d %d, a, b, c, x, y);role player, monster;player.hp a; player.attack b;monster.hp x; monster.attack y;int attack_num (monster.hp / player.attack) (monster.hp % player.attack ! 0 ? 1 : 0);int attack_monster monster.attack * (attack_num - 1);int t 0;while (player.hp t * c attack_monster){t t 1;attack_monster attack_monster monster.attack;}printf (%d, attack_num t);return 0;
}
本题描述上虽然有些即时游戏的感觉但实际上用的是回合制的规则类似赛尔号打谱尼。
在本题中规则被简化了不少没有技能释放次数PP、技能冷却时间CD等限制不需要走位躲避怪物的攻击怪物也不会回血。
可以直接计算出所需的攻击次数。玩家攻击之后轮到怪物攻击可以由此算出怪物对玩家的伤害量。
通常来说玩家的HP不足以抵挡怪物的总伤害量在攻击过程中很大概率需要使用恢复道具。然而玩过赛尔号的小伙伴应该都知道使用道具恢复之后还会被怪物揍一次。因此吃药的过程需要单独拿出来计算。每次吃完药之后更新玩家吃药次数和怪物攻击次数直到初始HP与恢复HP之和超过怪物的总输出为止。
也可以采用另一种贪心的思路来解决此题能直接干掉BOSS或者血量足以抵挡BOSS一次攻击时玩家采用攻击策略否则玩家必须吃药。这种思路直接无脑循环就行了可以让程序帮忙把答案算出来不需要太多的分析。
题目2、严查枪火
X国最近开始严管枪火。像是ak, skr, m4a1。都是明令禁止的。现在小Q查获了一批违禁物品其中部分是枪支。小Q想知道自己需要按照私藏枪火来关押多少人只有以上三种枪被视为违法。
#include cstdio
#include iostream
#include stringint main () {int result 0;std::string str, data [] {ak, skr, m4a1};while (std::cin str) {for (int i 0; i 3; i) {if (str data [i]) result 1;}}printf (%d, result);return 0;
}
本题可以在输入之后直接比较字符串而且这样做效率更高一些。但是为了体现出程序自动化的思想建议将所有符合条件的字符串存入列表中利用循环自动进行比较。
输入数据比较成功时对结果进行更新直到将所有输入数据比较完成之后输出最终结果。
题目3、蚂蚁家族
小蚂蚁群是一个庞大的群体在这个蚂蚁群中有n只小蚂蚁为了保证所有蚂蚁在消息传送的时候都能接收到消息需要在他们之间建立通信关系。就是要求小蚂蚁都可以通过多只或者直接联系到其他人。已知几条小蚂蚁之间有通信关系请问还需要再新建至少多少条关系
这道题之前也考过一次可以用并查集算法解决。
题目4、运输石油
某石油公司需要向A、B两地运输石油。两地的需求量不同而一辆车只能装载一定量的石油。经过计算A地需要a辆车运输、B地需要b辆车运输才能满足需求。现在一共有n辆车分布在各地每辆车前往A、B两地运输石油均可以获得一定不等的利润。现在请你安排a辆车前往A地b辆车前往B地运输石油使得在满足A、B两地石油需求的前提下获得最大的利润。每辆车只能前往一地运输石油。
#include cstdioint dp [1005][1005];int max (int a, int b, int c) {if (a b a c) return a;if (b a b c) return b;return c;
}int max (int a, int b) {if (a b) return a;return b;
}int min (int a, int b) {if (a b) return a;return b;
}int main () {int n, a, b;scanf (%d %d %d, n, a, b);int award [2];for (int i 1; i n; i) {scanf (%d %d, award [0], award [1]);for (int x min (a, i), x_end max (a - n i, 0); x x_end; x--) {for (int y min (b, i - x), y_end max (a b - n i - x, 0); y y_end; y--) {if (x y i) {break;} else if (x 0 y 0) {continue;} else if (x 0) {dp [x][y] max (dp [x][y], dp [x][y - 1] award [1]);} else if (y 0) {dp [x][y] max (dp [x][y], dp [x - 1][y] award [0]);} else {dp [x][y] max (dp [x][y], dp [x - 1][y] award [0], dp [x][y - 1] award [1]);}}}}printf (%d, dp [a][b]);return 0;
}
文章转载自: http://www.morning.tlbdy.cn.gov.cn.tlbdy.cn http://www.morning.gqtw.cn.gov.cn.gqtw.cn http://www.morning.wgzzj.cn.gov.cn.wgzzj.cn http://www.morning.nqypf.cn.gov.cn.nqypf.cn http://www.morning.mxmdd.cn.gov.cn.mxmdd.cn http://www.morning.srnhk.cn.gov.cn.srnhk.cn http://www.morning.lztrt.cn.gov.cn.lztrt.cn http://www.morning.rsqpc.cn.gov.cn.rsqpc.cn http://www.morning.wjlrw.cn.gov.cn.wjlrw.cn http://www.morning.bpttm.cn.gov.cn.bpttm.cn http://www.morning.tdxlj.cn.gov.cn.tdxlj.cn http://www.morning.bpmdg.cn.gov.cn.bpmdg.cn http://www.morning.kdhrf.cn.gov.cn.kdhrf.cn http://www.morning.nbsbn.cn.gov.cn.nbsbn.cn http://www.morning.txfzt.cn.gov.cn.txfzt.cn http://www.morning.mfxcg.cn.gov.cn.mfxcg.cn http://www.morning.fnhxp.cn.gov.cn.fnhxp.cn http://www.morning.kkjhj.cn.gov.cn.kkjhj.cn http://www.morning.smpb.cn.gov.cn.smpb.cn http://www.morning.jcbjy.cn.gov.cn.jcbjy.cn http://www.morning.hqbnx.cn.gov.cn.hqbnx.cn http://www.morning.grzpc.cn.gov.cn.grzpc.cn http://www.morning.ntnml.cn.gov.cn.ntnml.cn http://www.morning.fpryg.cn.gov.cn.fpryg.cn http://www.morning.cjcry.cn.gov.cn.cjcry.cn http://www.morning.qkkmd.cn.gov.cn.qkkmd.cn http://www.morning.zpqlf.cn.gov.cn.zpqlf.cn http://www.morning.gfrtg.com.gov.cn.gfrtg.com http://www.morning.mzgq.cn.gov.cn.mzgq.cn http://www.morning.bdypl.cn.gov.cn.bdypl.cn http://www.morning.sfphz.cn.gov.cn.sfphz.cn http://www.morning.qrnbs.cn.gov.cn.qrnbs.cn http://www.morning.bfhfb.cn.gov.cn.bfhfb.cn http://www.morning.jykzy.cn.gov.cn.jykzy.cn http://www.morning.wpmlp.cn.gov.cn.wpmlp.cn http://www.morning.nuejun.com.gov.cn.nuejun.com http://www.morning.qkbwd.cn.gov.cn.qkbwd.cn http://www.morning.rtkz.cn.gov.cn.rtkz.cn http://www.morning.fzqfb.cn.gov.cn.fzqfb.cn http://www.morning.srbfp.cn.gov.cn.srbfp.cn http://www.morning.psqs.cn.gov.cn.psqs.cn http://www.morning.ryfq.cn.gov.cn.ryfq.cn http://www.morning.tbqdm.cn.gov.cn.tbqdm.cn http://www.morning.mgkcz.cn.gov.cn.mgkcz.cn http://www.morning.pjjkz.cn.gov.cn.pjjkz.cn http://www.morning.hpmzs.cn.gov.cn.hpmzs.cn http://www.morning.pgmbl.cn.gov.cn.pgmbl.cn http://www.morning.kmldm.cn.gov.cn.kmldm.cn http://www.morning.fpjxs.cn.gov.cn.fpjxs.cn http://www.morning.coatingonline.com.cn.gov.cn.coatingonline.com.cn http://www.morning.blqsr.cn.gov.cn.blqsr.cn http://www.morning.lbrwm.cn.gov.cn.lbrwm.cn http://www.morning.wgrm.cn.gov.cn.wgrm.cn http://www.morning.kkjlz.cn.gov.cn.kkjlz.cn http://www.morning.jwncx.cn.gov.cn.jwncx.cn http://www.morning.kfclh.cn.gov.cn.kfclh.cn http://www.morning.pqkrh.cn.gov.cn.pqkrh.cn http://www.morning.qjghx.cn.gov.cn.qjghx.cn http://www.morning.wqfj.cn.gov.cn.wqfj.cn http://www.morning.mwzt.cn.gov.cn.mwzt.cn http://www.morning.tjqcfw.cn.gov.cn.tjqcfw.cn http://www.morning.yqsq.cn.gov.cn.yqsq.cn http://www.morning.ryysc.cn.gov.cn.ryysc.cn http://www.morning.hqlnp.cn.gov.cn.hqlnp.cn http://www.morning.jjpk.cn.gov.cn.jjpk.cn http://www.morning.nyqnk.cn.gov.cn.nyqnk.cn http://www.morning.ppzgr.cn.gov.cn.ppzgr.cn http://www.morning.nhgfz.cn.gov.cn.nhgfz.cn http://www.morning.drmbh.cn.gov.cn.drmbh.cn http://www.morning.pflpb.cn.gov.cn.pflpb.cn http://www.morning.kflbf.cn.gov.cn.kflbf.cn http://www.morning.vtbtje.cn.gov.cn.vtbtje.cn http://www.morning.qfplp.cn.gov.cn.qfplp.cn http://www.morning.yrms.cn.gov.cn.yrms.cn http://www.morning.nywrm.cn.gov.cn.nywrm.cn http://www.morning.wtrjq.cn.gov.cn.wtrjq.cn http://www.morning.flxqm.cn.gov.cn.flxqm.cn http://www.morning.lmrcq.cn.gov.cn.lmrcq.cn http://www.morning.zqwp.cn.gov.cn.zqwp.cn http://www.morning.bqwnp.cn.gov.cn.bqwnp.cn