ZOJ 3897(模拟题)
来源:互联网 发布:php 招聘 编辑:程序博客网 时间:2024/05/12 16:21
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) andc(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
23 100200 150 2008 80200 100 100 100 100 80 160 200
Sample Output
23
#include <stdio.h>using namespace std;int arr[200];int main(){ int t; scanf("%d",&t); while(t--) { int n,c; scanf("%d%d",&n,&c); for(int i=1;i<=n;i++) scanf("%d",arr+i); int flag,num,res,cnt,i=1;//flag 方向 num 杀人数 res 结果 cnt 攻击次数 flag=num=res=cnt=0; while(1) { if(num==n||cnt==n+5)break; if(i==0)i=n; else if(i==n+1)i=1; if(flag==0) //向右 { if(arr[i]<=0) { i++; continue; } else { arr[i]-=c; cnt++; res=i; if(arr[i]<=0) { num++; flag=1; i--; } else i++; } } else if(flag==1) //向左 { if(arr[i]<=0) { i--; continue; } else { arr[i]-=c; cnt++; res=i; if(arr[i]<=0) { num++; flag=0; i++; } else i--; } } } printf("%d\n",res); } return 0;}
- ZOJ 3897(模拟题)
- ZOJ 3897 Fiddlesticks(模拟题)
- ZOJ 2108 Elevator (模拟题)
- ZOJ 3327Friend Number(模拟题)
- ZOJ 3607Lazier Salesgirl (模拟题)
- ZOJ 3705 Applications(模拟题)
- ZOJ 1138(模拟)
- ZOJ Fiddlesticks (简单模拟)
- ZOJ 3705Applications (模拟)
- ZOJ 3323(B)模拟
- ZOJ 3326(E)模拟
- ZOJ 3333(L)模拟
- ZOJ 3705 Applications (模拟)
- zoj 1274 Getting Chorded(啊,模拟题 = =)
- ZOJ - 3872 Beauty of Array (技巧&模拟)好题
- zoj 2958 (模拟题)待改正
- ZOJ 1274 Getting Chorded(模拟题)
- zoj 3327 Friend Number 模拟题
- 后台性能测试--性能测试方案设计
- [置顶] 我的Android进阶之旅------>Android中制作和查看自定义的Debug版本Android签名证书
- Linux系统脚本分析之rc.sysinit
- linux 终端的几个概念
- 使用Pydoc生成文档
- ZOJ 3897(模拟题)
- Spring4整合Hessian4(MavenWeb实例)
- Linux 空格和tab的替换
- js中 parseFloat() 函数
- Manacher算法求回文串兼leetcode 5Longest Palindromic Substring
- mybatis中 mapper.xml文件中,获取数组中指定的位置的数据
- 一、股市带动书市
- SSZipArchive 与 ZipArchive
- java hashcode