ZOJ-3897 Fiddlesticks
来源:互联网 发布:手机淘宝怎么看秒杀 编辑:程序博客网 时间:2024/06/05 10:01
#include <cstdio>#include <cstring>#include <queue>#include <iostream>using namespace std;int T, n, c, cnt, sum, ans;int HP[25];struct node{ int num; //HP的下标 int dir; //方向----正方向为1,反方向为-1} temp;void change(){ temp.num += temp.dir; if(temp.num < 0) //攻击第一个后 攻击最后一个 temp.num = n - 1; if(temp.num == n) //攻击最后一个后 攻击第一个 temp.num = 0;}void attack(){ queue <node> process; while(!process.empty()) process.pop(); temp.num = 0; //初始下标0 temp.dir = 1; //初始方向正向 process.push(temp); while(!process.empty()) { temp = process.front(); process.pop(); if(HP[temp.num] <= 0) //如果HP <= 0 投入下一个 对 cnt sum 不做处理 { if(temp.dir == 1) { change(); process.push(temp); } else { change(); process.push(temp); } continue; } HP[temp.num] -= c; //减少HP cnt --; //剩余攻击次数减少 if(!cnt) //如果攻击次数为0 弹出这次的num { ans = temp.num + 1; //因为num从0开始 break; } if(HP[temp.num] > 0) { change(); process.push(temp); } else { sum --; if(!sum) //如果敌人全死 弹出这次的num { ans = temp.num + 1; break; } temp.dir = - temp.dir; //杀死敌人后 反向攻击 change(); process.push(temp); } }}int main(){ scanf("%d", & T); while(T --) { scanf("%d %d", & n, & c); sum = n; //总敌人数(用来判断敌人是否全死) cnt = n + 5; //总攻击次数(用来判断是否可以继续攻击) for(int i = 0; i < n; i ++) scanf("%d", & HP[i]); attack(); //开始执行攻击 printf("%d\n", ans); }}
题意:
有n个敌人,稻草人E技能乌鸦最多能弹n + 5次,从1开始弹到最后,从最后弹到第1个(也就是循环弹)。每死一个敌人,乌鸦就会反向攻击。直到敌人死光或者攻击次数用完。输出最后一个被攻击的敌人序号。
题解:
用一个队列模拟过程,投进一个敌人的序号,如果HP>0,就攻击他并弹出(表示结束攻击),并按着方向,继续投入。
0 0
- ZOJ-3897 Fiddlesticks
- ZOJ 3897 Fiddlesticks
- ZOJ-3897-Fiddlesticks
- ZOJ-3897-Fiddlesticks
- ZOJ 3897 Fiddlesticks(模拟题)
- ZOJ Fiddlesticks (简单模拟)
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- 滑动窗口的最大值
- java开发中的23种设计模式详解
- CentOS6.5安装redis(3.0.3)
- 体会Collection
- hadoop MapReduce实例解析
- ZOJ-3897 Fiddlesticks
- vbox 使用中的疑难杂症
- POJ-1528
- asp.net页面之间的传值
- Unable to locate tools.jar. Expected to find it in D:\Java\jre8\lib\tools.jar
- IP首部校验和的计算
- matlab中去除矩阵中相同的行
- ISCC2014 writeup
- Mac下IntelliJ IDEA常用快捷键