【非常简单的】A.gamer hemose

题目来源

Problem - 1592A - CodeforcesCodeforces. Programming competitions and contests, programming communityhttps://codeforces.com/problemset/problem/1592/A

题干

解释

 先给武器能力值进行排序,然后只使用最强的和第二强的武器。一开始采用模拟算法结果TLE了

后来直接将两个武器并为一组,看看能用多少组,取剩下来的余数比较和最强武器的大小,然后输出结果,so easy

代码段

void solve()//gamer hemose
{
	int n, h;	
	cin >> n >> h;
	vector<int>a(n);
	for (auto &x : a)cin >> x;
	sort(a.begin(), a.begin()+n);//一定要传首地址
	int count;
	int sum = a[n - 1] + a[n - 2];
	if (h % sum == 0)cout << (h / sum)*2 << endl;
	else if (h % sum > a[n - 1])cout << (h / sum) * 2 + 2 << endl;
	else if (h % sum <= a[n - 1])cout << (h / sum) * 2 + 1 << endl;	
}

猜你喜欢

转载自blog.csdn.net/nathanqian123/article/details/121265301