ZOJ-3897-Fiddlesticks
来源:互联网 发布:js 删除style属性 编辑:程序博客网 时间:2024/05/16 07:10
ZOJ-3897-Fiddlesticks
Time Limit: 2 Seconds Memory Limit: 65536 KB
Fiddlesticks is a popular hero in LOL. When he uses third skill, he can summon a crow to attack one enemy while causing damage to the enemy. And then, the crow will attack another enemy. Now there are n enemies. Their HP respectively are a1,a2,a3,…,an. The crow can attack enemies for n+5 times in total. If all enemies are killed, the crow will also disappear.
Being attacked means the enemy’s HP minus crow’s damage. If a enemy’s HP is not larger than 0, the enemy will be removed from the game. In other word, the enemy is killed.
Fiddlesticks always let the crow attack the first enemy firstly. And the crow will attack the second enemy secondly. One by one,1st to nth enemy will be attacked. After attacking the nth enemy, the crow will return to the first enemy(if the enemy isn’t killed). But if the crow kills one enemy, it will reverse the attacking direction. For example, if crow kills the 5th enemy, it won’t attack 6th enemy and it will attack 4th enemy(if the enemy isn’t killed). What you have to get is the serial number of the enemy who was attack finally.
Input
The first line of the input contains a single integer T, the number of test cases, followed by the input data for each test case. In each test case, you should input n(2<=n<=20) and c(50<=c<=100) in one line. n is the number of enemies, and c is the damage of the crow. Then you should input the n enemies’ HP(50<=an<=200) in one line.
Output
The output contains exactly T lines, each corresponding to a test case. Each line should contain a single number that is the serial number of the enemy who was attacked finally.
Sample Input
2
3 100
200 150 200
8 80
200 100 100 100 100 80 160 200
Sample Output
2
3
题目链接:ZOJ 3897
题目思路: 设置dir变量,判断他的kill方向,进行模拟
以下是代码:
#include <vector>#include <map>#include <set>#include <algorithm>#include <iostream>#include <cstdio>#include <cmath>#include <cstdlib>#include <string>#include <cstring>using namespace std;int n,c;int a[1000] = {0};int main(){ int t; cin >> t; while(t--) { cin >> n >> c; for (int i = 0; i < n; i++) { cin >> a[i]; } int i = 0,dir = 1,k = n,num = n + 5; while(n > 1) { if (a[i] > c) { a[i] -= c; num--; } else if (a[i] > 0) { dir = (-1) * dir; a[i] = 0; n--; num--; } i = (i + dir + k) % k; if (num == 1) break; } while(a[i] == 0) i = (i + dir + k) % k; cout << (i + 1) << endl; } return 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
- nginx的accept互斥锁
- ACM学习-动态规划-子问题编码
- 打开新的页面.HTML
- uva10810(求逆序数)
- 对于JVM的浅解
- ZOJ-3897-Fiddlesticks
- 如何将Eclipse中的项目迁移到Android Studio 中
- 重识面向对象
- 友盟统计不生效问题查找与解决
- Codeforces Round #321 (Div. 2)
- 【kmp】算法总结
- 5-4 是否同一棵二叉搜索树 (25分)
- HDU-5122 K.Bro Sorting(贪心)
- pat1017Queueing at Bank (25)