CodeForces - 1592A Gamer Hemose排序
Posted 海岛Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces - 1592A Gamer Hemose排序相关的知识,希望对你有一定的参考价值。
A. Gamer Hemose
time limit per test 1 second
memory limit per test 256 megabytes
One day, Ahmed_Hossam went to Hemose and said “Let’s solve a gym contest!”. Hemose didn’t want to do that, as he was playing Valorant, so he came up with a problem and told it to Ahmed to distract him. Sadly, Ahmed can’t solve it… Could you help him?
There is an Agent in Valorant, and he has n weapons. The i-th weapon has a damage value ai, and the Agent will face an enemy whose health value is H.
The Agent will perform one or more moves until the enemy dies.
In one move, he will choose a weapon and decrease the enemy’s health by its damage value. The enemy will die when his health will become less than or equal to 0. However, not everything is so easy: the Agent can’t choose the same weapon for 2 times in a row.
What is the minimum number of times that the Agent will need to use the weapons to kill the enemy?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤105). Description of the test cases follows.
The first line of each test case contains two integers n and H (2≤n≤103,1≤H≤109) — the number of available weapons and the initial health value of the enemy.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — the damage values of the weapons.
It’s guaranteed that the sum of n over all test cases doesn’t exceed 2⋅105.
Output
For each test case, print a single integer — the minimum number of times that the Agent will have to use the weapons to kill the enemy.
Example
input
3
2 4
3 7
2 6
4 2
3 11
2 1 7
output
1
2
3
Note
In the first test case, the Agent can use the second weapon, making health value of the enemy equal to 4−7=−3. −3≤0, so the enemy is dead, and using weapon 1 time was enough.
In the second test case, the Agent can use the first weapon first, and then the second one. After this, the health of enemy will drop to 6−4−2=0, meaning he would be killed after using weapons 2 times.
In the third test case, the Agent can use the weapons in order (third, first, third), decreasing the health value of enemy to 11−7−2−7=−5 after using the weapons 3 times. Note that we can’t kill the enemy by using the third weapon twice, as even though 11−7−7<0, it’s not allowed to use the same weapon twice in a row.
问题链接:CodeForces - 1592A Gamer Hemose
问题简述:(略)
问题分析:(略)
AC的C++语言程序如下:
/* CodeForces - 1592A Gamer Hemose */
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int N = 1000;
int a[N];
int main()
int t, n, k;
scanf("%d", &t);
while (t--)
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
sort(a, a + n);
int sum = a[n - 2] + a[n - 1];
int ans = k / sum * 2;
if (k % sum == 0) ;
else if (k % sum <= a[n - 1]) ans++;
else ans += 2;
printf("%d\\n", ans);
return 0;
以上是关于CodeForces - 1592A Gamer Hemose排序的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #746 (Div. 2)(A,B,C)
Codeforces Round #746 (Div. 2)(A,B,C)
未来是属于HTML5,还是属于APP? | Gamer 2015